/*
* call-seq:
* strio.each_char {|char| block } -> strio
*
* See IO#each_char.
*/
static VALUE
strio_each_char(self)
VALUE self;
{
struct StringIO *sio;
VALUE str;
const char *ptr;
size_t len;
RETURN_ENUMERATOR(self, 0, 0);
sio = readable(StringIO(self));
str = sio->string;
ptr = RSTRING_PTR(str);
len = RSTRING_LEN(str);
while (sio->pos < len) {
int pos = sio->pos;
char c = ptr[pos];
int n = mbclen(c);
if (len < pos + n) n = len - pos;
sio->pos += n;
rb_yield(rb_str_substr(str, pos, n));
}
return self;
}