diff options
author | glass <glass@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-07-31 11:18:18 +0000 |
---|---|---|
committer | glass <glass@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-07-31 11:18:18 +0000 |
commit | 0e2d0bb9705c21c4cfecf68a9ccf6c54e040d667 (patch) | |
tree | 0a824b3c7c4ffd6526896c51e8f0ec9629d20cef /string.c | |
parent | aba8c29a8b3a2921009eca50bfb08bea03ec4164 (diff) | |
download | ruby-0e2d0bb9705c21c4cfecf68a9ccf6c54e040d667.tar.gz |
* string.c (rb_str_rindex): fix bug introduced in r42269.
"".rindex("") should return 0.
(str_rindex): ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42275 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'string.c')
-rw-r--r-- | string.c | 11 |
1 files changed, 6 insertions, 5 deletions
@@ -2667,19 +2667,20 @@ rb_str_index_m(int argc, VALUE *argv, VALUE str) return LONG2NUM(pos); } -#if HAVE_MEMRCHR +#ifdef HAVE_MEMRCHR static long -str_rindex(VALUE str, VALUE sub, const char *s, rb_encoding *enc) +str_rindex(VALUE str, VALUE sub, const char *s, long pos, rb_encoding *enc) { char *hit, *adjusted; int c; long slen, searchlen; char *sbeg, *e, *t; + slen = RSTRING_LEN(sub); + if (slen == 0) return pos; sbeg = RSTRING_PTR(str); e = RSTRING_END(str); t = RSTRING_PTR(sub); - slen = RSTRING_LEN(sub); c = *t & 0xff; searchlen = s - sbeg + 1; @@ -2701,7 +2702,7 @@ str_rindex(VALUE str, VALUE sub, const char *s, rb_encoding *enc) } #else static long -str_rindex(VALUE str, VALUE sub, const char *s, rb_encoding *enc) +str_rindex(VALUE str, VALUE sub, const char *s, long pos, rb_encoding *enc) { long slen; char *sbeg, *e, *t; @@ -2753,7 +2754,7 @@ rb_str_rindex(VALUE str, VALUE sub, long pos) } s = str_nth(sbeg, RSTRING_END(str), pos, enc, singlebyte); - return str_rindex(str, sub, s, enc); + return str_rindex(str, sub, s, pos, enc); } |