I am writing a C extension for Ruby, and I need to accept a string as a parameter, and iterate the characters in the string. My code below works fine for ASCII characters, but it does not handle multiple byte characters, and outputs "garbage" instead. I could not find any sample code that would iterate over unicode strings. I would appreciate any pointers.
static VALUE test_method(VALUE self, VALUE text)
{
char *pch;
char *pch_end = RSTRING_END(text);
for (pch = RSTRING_PTR(text); pch < pch_end; pch++)
{
printf("%c\n", *pch);
}
...
}