mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* re.c (match_select): restore previous behavior of MatchData#select.
RDoc updated as well, mentioning the plan to remove this method in the future. [ruby-dev:34556] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@16263 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
4f811857fa
commit
eb416323bf
2 changed files with 46 additions and 2 deletions
|
@ -1,3 +1,9 @@
|
|||
Fri May 2 13:47:51 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||
|
||||
* re.c (match_select): restore previous behavior of MatchData#select.
|
||||
RDoc updated as well, mentioning the plan to remove this method
|
||||
in the future. [ruby-dev:34556]
|
||||
|
||||
Fri May 2 13:04:04 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||
|
||||
* ext/dbm/dbm.c (Init_dbm): defines DBM::VERSION even when
|
||||
|
|
42
re.c
42
re.c
|
@ -1219,7 +1219,6 @@ match_entry(match, n)
|
|||
/*
|
||||
* call-seq:
|
||||
* mtch.values_at([index]*) => array
|
||||
* mtch.select([index]*) => array
|
||||
*
|
||||
* Uses each <i>index</i> to access the matching values, returning an array of
|
||||
* the corresponding matches.
|
||||
|
@ -1239,6 +1238,45 @@ match_values_at(argc, argv, match)
|
|||
}
|
||||
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* mtch.select{|obj| block} => array
|
||||
*
|
||||
* Returns an array containing match strings for which <em>block</em>
|
||||
* gives <code>true</code>. MatchData#select will be removed from Ruby 1.9.
|
||||
*
|
||||
* m = /(.)(.)(\d+)(\d)/.match("THX1138: The Movie")
|
||||
* p m.select{|x| /X/ =~ x} #=> ["HX1138", "X"]
|
||||
*/
|
||||
|
||||
static VALUE
|
||||
match_select(argc, argv, match)
|
||||
int argc;
|
||||
VALUE *argv;
|
||||
VALUE match;
|
||||
{
|
||||
if (argc > 0) {
|
||||
rb_raise(rb_eArgError, "wrong number of arguments (%d for 0)", argc);
|
||||
}
|
||||
else {
|
||||
struct re_registers *regs = RMATCH(match)->regs;
|
||||
VALUE target = RMATCH(match)->str;
|
||||
VALUE result = rb_ary_new();
|
||||
int i;
|
||||
int taint = OBJ_TAINTED(match);
|
||||
|
||||
for (i=0; i<regs->num_regs; i++) {
|
||||
VALUE str = rb_str_substr(target, regs->beg[i], regs->end[i]-regs->beg[i]);
|
||||
if (taint) OBJ_TAINT(str);
|
||||
if (RTEST(rb_yield(str))) {
|
||||
rb_ary_push(result, str);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
|
@ -2326,7 +2364,7 @@ Init_Regexp()
|
|||
rb_define_method(rb_cMatch, "[]", match_aref, -1);
|
||||
rb_define_method(rb_cMatch, "captures", match_captures, 0);
|
||||
rb_define_method(rb_cMatch, "values_at", match_values_at, -1);
|
||||
rb_define_method(rb_cMatch, "select", match_values_at, -1);
|
||||
rb_define_method(rb_cMatch, "select", match_select, -1);
|
||||
rb_define_method(rb_cMatch, "pre_match", rb_reg_match_pre, 0);
|
||||
rb_define_method(rb_cMatch, "post_match", rb_reg_match_post, 0);
|
||||
rb_define_method(rb_cMatch, "to_s", match_to_s, 0);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue