aboutsummaryrefslogtreecommitdiffstats
path: root/io.c
diff options
context:
space:
mode:
Diffstat (limited to 'io.c')
-rw-r--r--io.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/io.c b/io.c
index 104f521378..fc973bc5c8 100644
--- a/io.c
+++ b/io.c
@@ -3763,8 +3763,25 @@ rb_io_each_codepoint(VALUE io)
rb_yield(UINT2NUM(c));
}
else if (MBCLEN_INVALID_P(r)) {
+ invalid:
rb_raise(rb_eArgError, "invalid byte sequence in %s", rb_enc_name(enc));
}
+ else if (MBCLEN_NEEDMORE_P(r)) {
+ char cbuf[8], *p = cbuf;
+ int more = MBCLEN_NEEDMORE_LEN(r);
+ if (more > numberof(cbuf)) goto invalid;
+ more += n = fptr->rbuf.len;
+ if (more > numberof(cbuf)) goto invalid;
+ while ((n = (int)read_buffered_data(p, more, fptr)) > 0 &&
+ (p += n, (more -= n) > 0)) {
+ if (io_fillbuf(fptr) < 0) goto invalid;
+ if ((n = fptr->rbuf.len) > more) n = more;
+ }
+ r = rb_enc_precise_mbclen(cbuf, p, enc);
+ if (!MBCLEN_CHARFOUND_P(r)) goto invalid;
+ c = rb_enc_codepoint(cbuf, p, enc);
+ rb_yield(UINT2NUM(c));
+ }
else {
continue;
}