diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-06-19 08:25:50 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-06-19 08:25:50 +0000 |
commit | 768380583a4a2527994fa33e78fdcfbeee20b6a8 (patch) | |
tree | e17a61055e26352f4e1aba0de3d7ef5f57080b40 | |
parent | 363b0bddde815a459f04e1d167d56bd1f498275c (diff) | |
download | ruby-768380583a4a2527994fa33e78fdcfbeee20b6a8.tar.gz |
* string.c (rb_str_scan): String#scan should preserve last
successful match data. [ruby-dev:35106]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@17426 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | string.c | 11 |
2 files changed, 12 insertions, 4 deletions
@@ -1,3 +1,8 @@ +Thu Jun 19 17:19:14 2008 Yukihiro Matsumoto <matz@ruby-lang.org> + + * string.c (rb_str_scan): String#scan should preserve last + successful match data. [ruby-dev:35106] + Thu Jun 19 16:49:36 2008 NAKAMURA Usaku <usa@ruby-lang.org> * missing/acosh.c (atanh): should set ERANGE to errno if parameter @@ -5689,7 +5689,7 @@ rb_str_scan(VALUE str, VALUE pat) { VALUE result; long start = 0; - VALUE match = Qnil; + long last = -1, prev = 0; char *p = RSTRING_PTR(str); long len = RSTRING_LEN(str); pat = get_pat(pat, 1); @@ -5697,18 +5697,21 @@ rb_str_scan(VALUE str, VALUE pat) VALUE ary = rb_ary_new(); while (!NIL_P(result = scan_once(str, pat, &start))) { - match = rb_backref_get(); + last = prev; + prev = start; rb_ary_push(ary, result); } - rb_backref_set(match); + if (last >= 0) rb_reg_search(pat, str, last, 0); return ary; } while (!NIL_P(result = scan_once(str, pat, &start))) { + last = prev; + prev = start; rb_yield(result); str_mod_check(str, p, len); } - rb_backref_set(match); + if (last >= 0) rb_reg_search(pat, str, last, 0); return str; } |