Modified: MacRuby/trunk/string.c (170 => 171)
--- 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 (170 => 171)
--- 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