summaryrefslogtreecommitdiff
path: root/re.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-05-04 16:03:24 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-05-04 16:03:24 +0000
commitf595d5b0d24d9b0323aba79ae07a6e1c9dbfbe36 (patch)
treea6f751d98db26e466d957576ef3fee9974cbb471 /re.c
parentf001f2f6d584d948b9b321171875ee872048df23 (diff)
* array.c (rb_ary_values_at): new method to replace select(index..).
* hash.c (rb_hash_values_at,env_values_at): ditto. * re.c (match_values_at): ditto. * struct.c (rb_struct_values_at): ditto. * re.c (match_select): add iterator behavior. * ext/curses/curses.c, ext/digest/sha2/sha2.c, ext/iconv/iconv.c, ext/racc/cparse/cparse.c: include "ruby.h" at the top to shut up "_FILE_OFFSET_BITS redefined" warning on Solaris. * class.c (rb_class_protected_instance_methods): now gives warnings to show migration path. The default will be reversed on Jan 2004. * numeric.c (num_step): "1.1.step(1.5,0.1)" to work. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3754 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 're.c')
-rw-r--r--re.c31
1 files changed, 30 insertions, 1 deletions
diff --git a/re.c b/re.c
index 9dd9d9bc4d..2bb0411bc0 100644
--- a/re.c
+++ b/re.c
@@ -953,7 +953,7 @@ match_aref(argc, argv, match)
}
static VALUE
-match_select(argc, argv, match)
+match_values_at(argc, argv, match)
int argc;
VALUE *argv;
VALUE match;
@@ -981,6 +981,34 @@ match_select(argc, argv, match)
}
static VALUE
+match_select(argc, argv, match)
+ int argc;
+ VALUE *argv;
+ VALUE match;
+{
+ if (!rb_block_given_p()) {
+ rb_warn("MatchData#select(index..) is deprecated; use MatchData#values_at");
+ return match_values_at(argc, argv, match);
+ }
+ 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 (rb_yield(str)) {
+ rb_ary_push(result, str);
+ }
+ }
+ return result;
+ }
+}
+
+static VALUE
match_to_s(match)
VALUE match;
{
@@ -1715,6 +1743,7 @@ Init_Regexp()
rb_define_method(rb_cMatch, "to_a", match_to_a, 0);
rb_define_method(rb_cMatch, "[]", match_aref, -1);
rb_define_method(rb_cMatch, "select", match_select, -1);
+ rb_define_method(rb_cMatch, "values_at", match_values_at, -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);