From 30e7d0c6efccaae8c935d7e5269e9cd6fe1154ab Mon Sep 17 00:00:00 2001 From: nobu Date: Fri, 7 Feb 2003 06:35:26 +0000 Subject: * intern.h, re.c (rb_memsearch): returns long. * string.c (rb_str_index): should return offset position. git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@3455 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- string.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'string.c') diff --git a/string.c b/string.c index 0cadd61fe..3dca59b6d 100644 --- a/string.c +++ b/string.c @@ -839,14 +839,18 @@ rb_str_index(str, sub, offset) VALUE str, sub; long offset; { + long pos; + if (offset < 0) { offset += RSTRING(str)->len; if (offset < 0) return -1; } if (RSTRING(str)->len - offset < RSTRING(sub)->len) return -1; if (RSTRING(sub)->len == 0) return offset; - return rb_memsearch(RSTRING(sub)->ptr, RSTRING(sub)->len, + pos = rb_memsearch(RSTRING(sub)->ptr, RSTRING(sub)->len, RSTRING(str)->ptr+offset, RSTRING(str)->len-offset); + if (pos < 0) return pos; + return pos + offset; } static VALUE -- cgit