diff options
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | string.c | 6 |
2 files changed, 8 insertions, 3 deletions
@@ -1,3 +1,8 @@ +2010-09-24 NARUSE, Yui <naruse@ruby-lang.org> + + * string.c (rb_str_rindex): use rb_enc_prev_char instead of repeated str_nth. + patched by Michael Selig [ruby-core:32498] + Fri Sep 24 14:19:12 2010 URABE Shyouhei <shyouhei@ruby-lang.org> * test/test_pty.rb: Same as 229281; existence of PTY class do not @@ -2488,14 +2488,14 @@ rb_str_rindex(VALUE str, VALUE sub, long pos) e = RSTRING_END(str); t = RSTRING_PTR(sub); slen = RSTRING_LEN(sub); - for (;;) { - s = str_nth(sbeg, e, pos, enc, singlebyte); - if (!s) return -1; + s = str_nth(sbeg, e, pos, enc, singlebyte); + while (s) { if (memcmp(s, t, slen) == 0) { return pos; } if (pos == 0) break; pos--; + s = rb_enc_prev_char(sbeg, s, e, enc); } return -1; } |