[macruby-changes] [3795] MacRuby/trunk/string.c

source_changes at macosforge.org source_changes at macosforge.org
Wed Mar 17 22:02:24 PDT 2010


Revision: 3795
          http://trac.macosforge.org/projects/ruby/changeset/3795
Author:   lsansonetti at apple.com
Date:     2010-03-17 22:02:24 -0700 (Wed, 17 Mar 2010)
Log Message:
-----------
fix some bugs in #index

Modified Paths:
--------------
    MacRuby/trunk/string.c

Modified: MacRuby/trunk/string.c
===================================================================
--- MacRuby/trunk/string.c	2010-03-18 03:49:19 UTC (rev 3794)
+++ MacRuby/trunk/string.c	2010-03-18 05:02:24 UTC (rev 3795)
@@ -1887,7 +1887,7 @@
 	if (pos < 0) {
 	    pos += len;
 	}
-	if (pos < 0 || pos >= len) {
+	if (pos < 0) {
 	    if (TYPE(sub) == T_REGEXP) {
 		rb_backref_set(Qnil);
 	    }
@@ -1900,6 +1900,9 @@
 
     switch (TYPE(sub)) {
 	case T_REGEXP:
+	    if (pos > len) {
+		return Qnil;
+	    }
 	    pos = rb_reg_search(sub, self, pos, false);
 	    break;
 
@@ -1907,8 +1910,13 @@
 	    StringValue(sub);
 	    // fall through
 	case T_STRING:
-	    pos = str_index_for_string(RSTR(self), str_need_string(sub),
-		    pos, -1, false, true);
+	    if (pos == len && rb_str_chars_len(sub) == 0) {
+		// Do nothing... RubySpec compliance...
+	    }
+	    else {
+		pos = str_index_for_string(RSTR(self), str_need_string(sub),
+			pos, -1, false, true);
+	    }
 	    break;
     }
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20100317/4abaed0b/attachment-0001.html>


More information about the macruby-changes mailing list