diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 1999-06-25 09:02:52 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 1999-06-25 09:02:52 +0000 |
commit | 01a24da8d31dad0bd15b96a4527dbccb345c6a78 (patch) | |
tree | cd137ccc900fd4fc9d4932059aed25eed41f8c62 /string.c | |
parent | 031d2e84df58ed54948671931544c41cf32da1ca (diff) |
990625
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_3@492 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'string.c')
-rw-r--r-- | string.c | 14 |
1 files changed, 7 insertions, 7 deletions
@@ -623,10 +623,10 @@ rb_str_rindex(argc, argv, str) if (rb_scan_args(argc, argv, "11", &sub, &position) == 2) { pos = NUM2INT(position); - if (pos > RSTRING(str)->len) return Qnil; + if (pos > RSTRING(str)->len) pos = RSTRING(str)->len; } else { - pos = 0; + pos = RSTRING(str)->len; } switch (TYPE(sub)) { @@ -637,9 +637,9 @@ rb_str_rindex(argc, argv, str) case T_STRING: /* substring longer than string */ - if (RSTRING(str)->len - pos < RSTRING(sub)->len) return Qnil; - sbeg = RSTRING(str)->ptr + pos; - s = RSTRING(str)->ptr + RSTRING(str)->len - RSTRING(sub)->len; + if (pos < RSTRING(sub)->len) return Qnil; + sbeg = RSTRING(str)->ptr; + s = RSTRING(str)->ptr + pos - RSTRING(sub)->len; t = RSTRING(sub)->ptr; len = RSTRING(sub)->len; while (sbeg <= s) { @@ -653,8 +653,8 @@ rb_str_rindex(argc, argv, str) case T_FIXNUM: { int c = FIX2INT(sub); - char *p = RSTRING(str)->ptr + RSTRING(str)->len - 1; - char *pbeg = RSTRING(str)->ptr + pos; + char *p = RSTRING(str)->ptr + pos - 1; + char *pbeg = RSTRING(str)->ptr; while (pbeg <= p) { if (*p == c) return INT2NUM(p - RSTRING(str)->ptr); |