mirror of
https://github.com/ruby/ruby.git
synced 2025-08-28 15:36:16 +02:00
string.c: search by rb_str_index
* re.c (match_regexp): set regexp for MatchData from string. * re.c (rb_backref_set_string): create MatchData from string and set backref. * string.c (rb_pat_search, rb_str_sub, rb_str_sub_bang, str_gsub), (scan_once, rb_str_scan, rb_str_partition): use rb_str_index instead of rb_reg_search() when pattern is a String. based on the patch by Sam Rawlins <sam.rawlins@gmail.com> [Fixes GH-579] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45451 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
227a5a2aae
commit
5752b61d86
5 changed files with 169 additions and 57 deletions
|
@ -831,6 +831,8 @@ class TestString < Test::Unit::TestCase
|
|||
c.force_encoding Encoding::US_ASCII
|
||||
|
||||
assert_equal Encoding::UTF_8, a.gsub(/world/, c).encoding
|
||||
|
||||
assert_equal S("a\u{e9}apos<"), S("a\u{e9}'<").gsub("'", "apos")
|
||||
end
|
||||
|
||||
def test_gsub!
|
||||
|
@ -1454,6 +1456,12 @@ class TestString < Test::Unit::TestCase
|
|||
o = Object.new
|
||||
def o.to_s; self; end
|
||||
assert_match(/^foo#<Object:0x.*>baz$/, "foobarbaz".sub("bar") { o })
|
||||
|
||||
assert_equal(S("Abc"), S("abc").sub("a", "A"))
|
||||
m = nil
|
||||
assert_equal(S("Abc"), S("abc").sub("a") {m = $~; "A"})
|
||||
assert_equal(S("a"), m[0])
|
||||
assert_equal(/a/, m.regexp)
|
||||
end
|
||||
|
||||
def test_sub!
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue