ruby-changes:4769
From: ko1@a...
Date: Fri, 2 May 2008 13:52:28 +0900 (JST)
Subject: [ruby-changes:4769] matz - Ruby:r16263 (ruby_1_8): * re.c (match_select): restore previous behavior of MatchData#select.
matz 2008-05-02 13:51:58 +0900 (Fri, 02 May 2008)
New Revision: 16263
Modified files:
branches/ruby_1_8/ChangeLog
branches/ruby_1_8/re.c
Log:
* 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]
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8/re.c?r1=16263&r2=16262&diff_format=u
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8/ChangeLog?r1=16263&r2=16262&diff_format=u
Index: ruby_1_8/ChangeLog
===================================================================
--- ruby_1_8/ChangeLog (revision 16262)
+++ ruby_1_8/ChangeLog (revision 16263)
@@ -1,3 +1,9 @@
+Fri May 2 13:47:51 2008 Yukihiro Matsumoto <matz@r...>
+
+ * 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@r...>
* ext/dbm/dbm.c (Init_dbm): defines DBM::VERSION even when
Index: ruby_1_8/re.c
===================================================================
--- ruby_1_8/re.c (revision 16262)
+++ ruby_1_8/re.c (revision 16263)
@@ -1219,7 +1219,6 @@
/*
* 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,7 +1238,46 @@
}
+/*
+ * 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:
* mtch.to_s => str
@@ -2326,7 +2364,7 @@
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);
--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/