aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-05-17 18:16:08 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-05-17 18:16:08 +0000
commit106679b0afaf26644192cbe5a916dac52a1928d2 (patch)
tree70720070a6362c164108e12b5b152591cdb9de49
parentb0b7c79e03f62dfd271d468b3f4651ccea6f3bd9 (diff)
downloadruby-106679b0afaf26644192cbe5a916dac52a1928d2.tar.gz
re.c: fix up r55036
* re.c (match_values_at): fix regression at r55036. MatchData#values_at accepts Range. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55039 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog5
-rw-r--r--re.c24
-rw-r--r--test/ruby/test_regexp.rb1
3 files changed, 27 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index a172ed0761..b422f0ed0c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Wed May 18 03:16:06 2016 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * re.c (match_values_at): fix regression at r55036.
+ MatchData#values_at accepts Range.
+
Wed May 18 02:02:58 2016 NARUSE, Yui <naruse@ruby-lang.org>
* re.c (match_aref): remove useless condition and call rb_fix2int.
diff --git a/re.c b/re.c
index 091168528f..ae8e2caf05 100644
--- a/re.c
+++ b/re.c
@@ -1921,6 +1921,7 @@ match_aref(int argc, VALUE *argv, VALUE match)
static VALUE
match_values_at(int argc, VALUE *argv, VALUE match)
{
+ struct re_registers *regs = RMATCH_REGS(match);
VALUE result;
int i;
@@ -1928,14 +1929,31 @@ match_values_at(int argc, VALUE *argv, VALUE match)
result = rb_ary_new2(argc);
for (i=0; i<argc; i++) {
+ VALUE tmp;
+ int num;
+ long beg, len, olen;
if (FIXNUM_P(argv[i])) {
rb_ary_push(result, rb_reg_nth_match(FIX2INT(argv[i]), match));
+ continue;
}
- else {
- int num = namev_to_backref_number(RMATCH_REGS(match), RMATCH(match)->regexp, argv[i]);
- if (num < 0) num = NUM2INT(argv[i]);
+ num = namev_to_backref_number(regs, RMATCH(match)->regexp, argv[i]);
+ if (num >= 0) {
rb_ary_push(result, rb_reg_nth_match(num, match));
+ continue;
+ }
+ /* check if idx is Range */
+ olen = regs->num_regs;
+ if (rb_range_beg_len(argv[i], &beg, &len, olen, 1)) {
+ long j, end = olen < beg+len ? olen : beg+len;
+ for (j = beg; j < end; j++) {
+ rb_ary_push(result, rb_reg_nth_match((int)j, match));
+ }
+ if (beg + len > j)
+ rb_ary_resize(result, RARRAY_LEN(result) + (beg + len) - j);
+ continue;
}
+ tmp = rb_to_int(argv[i]);
+ rb_ary_push(result, rb_reg_nth_match(NUM2INT(tmp), match));
}
return result;
}
diff --git a/test/ruby/test_regexp.rb b/test/ruby/test_regexp.rb
index aea2f2f6ea..a8a120cf3f 100644
--- a/test/ruby/test_regexp.rb
+++ b/test/ruby/test_regexp.rb
@@ -383,6 +383,7 @@ class TestRegexp < Test::Unit::TestCase
def test_match_values_at
m = /(...)(...)(...)(...)?/.match("foobarbaz")
assert_equal(["foo", "bar", "baz"], m.values_at(1, 2, 3))
+ assert_equal(["foo", "bar", "baz"], m.values_at(1..3))
m = /(?<a>\d+) *(?<op>[+\-*\/]) *(?<b>\d+)/.match("1 + 2")
assert_equal(["1", "2", "+"], m.values_at(:a, 'b', :op))