diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-01-22 00:26:49 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-01-22 00:26:49 +0000 |
commit | 157664b9f3cfeb485abe1cf8298e82accef23acf (patch) | |
tree | bbbdfa331d7379489ba826a015cdbf77231d4ecd | |
parent | 02f4dcca2cbe9b82987deeaa68d6e54c063128ba (diff) | |
download | ruby-157664b9f3cfeb485abe1cf8298e82accef23acf.tar.gz |
* string.c (rb_str_each_char): iterates over a shadow.
[ruby-dev:33243]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15165 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-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; } |