mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@14340 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
a927483326
commit
77629d2cbe
4 changed files with 23 additions and 3 deletions
|
@ -27,6 +27,14 @@ Wed Dec 19 22:59:52 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||||
* string.c (rb_str_rindex): comparison length should be based on
|
* string.c (rb_str_rindex): comparison length should be based on
|
||||||
bytes, not characters.
|
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@ruby-lang.org>
|
Wed Dec 19 21:42:18 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* re.c (rb_reg_regsub): should set checked encoding.
|
* re.c (rb_reg_regsub): should set checked encoding.
|
||||||
|
|
3
re.c
3
re.c
|
@ -2146,7 +2146,8 @@ reg_match_pos(VALUE re, VALUE *strp, long pos)
|
||||||
*strp = str = reg_operand(str, Qtrue);
|
*strp = str = reg_operand(str, Qtrue);
|
||||||
if (pos != 0) {
|
if (pos != 0) {
|
||||||
if (pos < 0) {
|
if (pos < 0) {
|
||||||
pos += RSTRING_LEN(str);
|
VALUE l = rb_str_length(str);
|
||||||
|
pos += NUM2INT(l);
|
||||||
if (pos < 0) {
|
if (pos < 0) {
|
||||||
return pos;
|
return pos;
|
||||||
}
|
}
|
||||||
|
|
1
string.c
1
string.c
|
@ -1650,7 +1650,6 @@ rb_str_rindex_m(int argc, VALUE *argv, VALUE str)
|
||||||
}
|
}
|
||||||
/* fall through */
|
/* fall through */
|
||||||
case T_STRING:
|
case T_STRING:
|
||||||
pos = str_sublen(str, pos, enc);
|
|
||||||
pos = rb_str_rindex(str, sub, pos);
|
pos = rb_str_rindex(str, sub, pos);
|
||||||
if (pos >= 0) return LONG2NUM(pos);
|
if (pos >= 0) return LONG2NUM(pos);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -1303,7 +1303,7 @@ class TestM17N < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_str_insert
|
def test_str_insert
|
||||||
combination(STRINGS, -2..2, STRINGS) {|s1, nth, s2|
|
combination(STRINGS, 0..2, STRINGS) {|s1, nth, s2|
|
||||||
t1 = s1.dup
|
t1 = s1.dup
|
||||||
t2 = s1.dup
|
t2 = s1.dup
|
||||||
begin
|
begin
|
||||||
|
@ -1317,6 +1317,18 @@ class TestM17N < Test::Unit::TestCase
|
||||||
assert_equal(t1, t2, "t=#{encdump s1}; t.insert(#{nth},#{encdump s2}); t")
|
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")
|
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
|
end
|
||||||
|
|
||||||
def test_str_intern
|
def test_str_intern
|
||||||
|
|
Loading…
Add table
Reference in a new issue