diff options
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | string.c | 13 |
2 files changed, 9 insertions, 9 deletions
@@ -1,3 +1,8 @@ +Tue Jan 22 09:26:47 2008 Nobuyoshi Nakada <nobu@ruby-lang.org> + + * string.c (rb_str_each_char): iterates over a shadow. + [ruby-dev:33243] + Tue Jan 22 08:59:52 2008 Eric Hodel <drbrain@segment7.net> * lib/rdoc/ri/formatter.rb: Indent labeled lists like note lists. @@ -4609,22 +4609,17 @@ static VALUE rb_str_each_char(VALUE str) { int i, len, n; - const char *ptr, *s; + const char *ptr; rb_encoding *enc; RETURN_ENUMERATOR(str, 0, 0); + str = rb_str_new4(str); ptr = RSTRING_PTR(str); len = RSTRING_LEN(str); enc = rb_enc_get(str); - n = rb_enc_mbclen(ptr, ptr + len, enc); - for (i = 0; i < len;) { + for (i = 0; i < len; i += n) { + n = rb_enc_mbclen(ptr + i, ptr + len, enc); rb_yield(rb_str_subseq(str, i, n)); - ptr = RSTRING_PTR(str); - len = RSTRING_LEN(str); - if ((i += n) >= len) break; - enc = rb_enc_get(str); - s = rb_enc_right_char_head(ptr, ptr + i, enc); - n = rb_enc_mbclen(s, ptr + len, enc); } return str; } |