[macruby-changes] [171] MacRuby/trunk

source_changes at macosforge.org source_changes at macosforge.org
Fri Apr 25 15:11:28 PDT 2008


Revision: 171
          http://trac.macosforge.org/projects/ruby/changeset/171
Author:   lsansonetti at apple.com
Date:     2008-04-25 15:11:27 -0700 (Fri, 25 Apr 2008)

Log Message:
-----------
fixing regressions in String#rindex

Modified Paths:
--------------
    MacRuby/trunk/string.c
    MacRuby/trunk/test/ruby/test_string.rb

Modified: MacRuby/trunk/string.c
===================================================================
--- MacRuby/trunk/string.c	2008-04-25 21:50:50 UTC (rev 170)
+++ MacRuby/trunk/string.c	2008-04-25 22:11:27 UTC (rev 171)
@@ -2661,6 +2661,14 @@
 {
 #if WITH_OBJC
     CFRange r;
+    long sublen, strlen;
+    sublen = RSTRING_CLEN(sub);
+    strlen = RSTRING_CLEN(str);
+    if (sublen == 0 && strlen == 0)
+	return 0;
+    if (pos <= sublen) {
+	pos = strlen < sublen ? strlen : sublen;
+    }
     return (CFStringFindWithOptions((CFStringRef)str, 
 		(CFStringRef)sub,
 		CFRangeMake(0, pos+1),

Modified: MacRuby/trunk/test/ruby/test_string.rb
===================================================================
--- MacRuby/trunk/test/ruby/test_string.rb	2008-04-25 21:50:50 UTC (rev 170)
+++ MacRuby/trunk/test/ruby/test_string.rb	2008-04-25 22:11:27 UTC (rev 171)
@@ -764,6 +764,9 @@
     assert_nil(S("hello").rindex(?z))
     assert_nil(S("hello").rindex(S("z")))
     assert_nil(S("hello").rindex(/z./))
+
+    assert_equal(0, S("hello").rindex(S("hello"), 0))
+    assert_equal(0, S("").rindex(S(""), 0))
   end
 
   def test_rjust

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/macruby-changes/attachments/20080425/f4bd08ff/attachment.html


More information about the macruby-changes mailing list