ruby-changes:2849
From: ko1@a...
Date: 20 Dec 2007 02:02:41 +0900
Subject: [ruby-changes:2849] matz - Ruby:r14340 (trunk): * string.c (rb_str_rindex_m): too much adjustment.
matz 2007-12-20 02:02:29 +0900 (Thu, 20 Dec 2007)
New Revision: 14340
Modified files:
trunk/ChangeLog
trunk/re.c
trunk/string.c
trunk/test/ruby/test_m17n.rb
Log:
* string.c (rb_str_rindex_m): too much adjustment.
* re.c (reg_match_pos): pos adjustment should be based on
characters.
* test/ruby/test_m17n.rb (TestM17N::test_str_insert): test updated
to check negative offset behavior.
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/string.c?r1=14340&r2=14339
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=14340&r2=14339
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/re.c?r1=14340&r2=14339
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/test/ruby/test_m17n.rb?r1=14340&r2=14339
Index: re.c
===================================================================
--- re.c (revision 14339)
+++ re.c (revision 14340)
@@ -2146,7 +2146,8 @@
*strp = str = reg_operand(str, Qtrue);
if (pos != 0) {
if (pos < 0) {
- pos += RSTRING_LEN(str);
+ VALUE l = rb_str_length(str);
+ pos += NUM2INT(l);
if (pos < 0) {
return pos;
}
Index: ChangeLog
===================================================================
--- ChangeLog (revision 14339)
+++ ChangeLog (revision 14340)
@@ -27,6 +27,14 @@
* string.c (rb_str_rindex): comparison length should be based on
bytes, not characters.
+ * string.c (rb_str_rindex_m): too much adjustment.
+
+ * re.c (reg_match_pos): pos adjustment should be based on
+ characters.
+
+ * test/ruby/test_m17n.rb (TestM17N::test_str_insert): test updated
+ to check negative offset behavior.
+
Wed Dec 19 21:42:18 2007 Nobuyoshi Nakada <nobu@r...>
* re.c (rb_reg_regsub): should set checked encoding.
Index: string.c
===================================================================
--- string.c (revision 14339)
+++ string.c (revision 14340)
@@ -1650,7 +1650,6 @@
}
/* fall through */
case T_STRING:
- pos = str_sublen(str, pos, enc);
pos = rb_str_rindex(str, sub, pos);
if (pos >= 0) return LONG2NUM(pos);
break;
Index: test/ruby/test_m17n.rb
===================================================================
--- test/ruby/test_m17n.rb (revision 14339)
+++ test/ruby/test_m17n.rb (revision 14340)
@@ -1303,7 +1303,7 @@
end
def test_str_insert
- combination(STRINGS, -2..2, STRINGS) {|s1, nth, s2|
+ combination(STRINGS, 0..2, STRINGS) {|s1, nth, s2|
t1 = s1.dup
t2 = s1.dup
begin
@@ -1317,6 +1317,18 @@
assert_equal(t1, t2, "t=#{encdump s1}; t.insert(#{nth},#{encdump s2}); t")
assert_equal(e1.class, e2.class, "begin #{encdump s1}.insert(#{nth},#{encdump s2}); rescue ArgumentError, IndexError => e; e end")
}
+ combination(STRINGS, -2..-1, STRINGS) {|s1, nth, s2|
+ next if s1.length + nth < 0
+ next unless s1.valid_encoding?
+ next unless s2.valid_encoding?
+ t1 = s1.dup
+ begin
+ t1.insert(nth, s2)
+ slen = s2.length
+ assert_equal(t1[nth-slen+1,slen], s2, "t=#{encdump s1}; t.insert(#{nth},#{encdump s2}); t")
+ rescue ArgumentError, IndexError => e
+ end
+ }
end
def test_str_intern
--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml