Feature #11100 » string_slice_many_captures.patch
| string.c | ||
|---|---|---|
|
static VALUE
|
||
|
rb_str_subpat(VALUE str, VALUE re, VALUE backref)
|
||
|
{
|
||
|
int i, nth;
|
||
|
if (rb_reg_search(re, str, 0, 0) >= 0) {
|
||
|
VALUE match = rb_backref_get();
|
||
|
int nth = rb_reg_backref_number(match, backref);
|
||
|
return rb_reg_nth_match(nth, match);
|
||
|
if (RB_TYPE_P(backref, T_ARRAY)) {
|
||
|
VALUE result = rb_ary_new();
|
||
|
for (i = 0; i < RARRAY_LEN(backref); i++) {
|
||
|
nth = rb_reg_backref_number(match, rb_ary_entry(backref, i));
|
||
|
rb_ary_push(result, rb_reg_nth_match(nth, match));
|
||
|
}
|
||
|
return result;
|
||
|
}
|
||
|
nth = rb_reg_backref_number(match, backref);
|
||
|
return rb_reg_nth_match(nth, match);
|
||
|
}
|
||
|
return Qnil;
|
||
|
}
|
||