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

source_changes at macosforge.org source_changes at macosforge.org
Thu Mar 18 19:10:36 PDT 2010


Revision: 3817
          http://trac.macosforge.org/projects/ruby/changeset/3817
Author:   lsansonetti at apple.com
Date:     2010-03-18 19:10:36 -0700 (Thu, 18 Mar 2010)
Log Message:
-----------
fixed a bunch of bugs in #rindex

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

Modified: MacRuby/trunk/string.c
===================================================================
--- MacRuby/trunk/string.c	2010-03-19 02:10:21 UTC (rev 3816)
+++ MacRuby/trunk/string.c	2010-03-19 02:10:36 UTC (rev 3817)
@@ -1003,7 +1003,7 @@
 	return 0;
     }
     if (searched->length_in_bytes == 0) {
-	return start_offset_in_bytes;
+	return backward_search ? end_offset_in_bytes : start_offset_in_bytes;
     }
     str_must_have_compatible_encoding(self, searched);
     str_make_same_format(self, searched);
@@ -1020,12 +1020,12 @@
     }
 
     if (backward_search) {
-	for (long offset_in_bytes = end_offset_in_bytes;
-		offset_in_bytes >= start_offset_in_bytes;
-		offset_in_bytes -= increment) {
-	    if (memcmp(self->data.bytes+offset_in_bytes, searched->data.bytes,
+	for (long offset = end_offset_in_bytes - increment;
+		offset >= start_offset_in_bytes;
+		offset -= increment) {
+	    if (memcmp(self->data.bytes + offset, searched->data.bytes,
 			searched->length_in_bytes) == 0) {
-		return offset_in_bytes;
+		return offset;
 	    }
 	}
     }
@@ -1033,12 +1033,12 @@
 	const long max_offset_in_bytes = end_offset_in_bytes
 	    - searched->length_in_bytes + 1;
 
-	for (long offset_in_bytes = start_offset_in_bytes;
-		offset_in_bytes < max_offset_in_bytes;
-		offset_in_bytes += increment) {
-	    if (memcmp(self->data.bytes+offset_in_bytes, searched->data.bytes,
+	for (long offset = start_offset_in_bytes;
+		offset < max_offset_in_bytes;
+		offset += increment) {
+	    if (memcmp(self->data.bytes + offset, searched->data.bytes,
 			searched->length_in_bytes) == 0) {
-		return offset_in_bytes;
+		return offset;
 	    }
 	}
     }
@@ -1956,11 +1956,11 @@
 	    }
 	}
 	if (pos >= len) {
-	    pos = len - 1;
+	    pos = len;
 	}
     }
     else {
-	pos = len - 1;
+	pos = len;
     }
 
     switch (TYPE(sub)) {
@@ -1972,8 +1972,10 @@
 	    StringValue(sub);
 	    // fall through
 	case T_STRING:
-	    pos = str_index_for_string(RSTR(self), str_need_string(sub),
-		    0, pos - 1, true, true);
+	    if (rb_str_chars_len(sub) > 0) {
+		pos = str_index_for_string(RSTR(self), str_need_string(sub),
+			0, pos, true, true);
+	    }
 	    break;
     }
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20100318/22ae6dcd/attachment.html>


More information about the macruby-changes mailing list