mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* re.c (rb_reg_s_union_m): Regexp.union accepts single argument which
is an array of patterns. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13638 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
ef1d280a4c
commit
dea669cf4e
2 changed files with 27 additions and 8 deletions
|
@ -1,3 +1,8 @@
|
|||
Fri Oct 5 21:24:59 2007 Tanaka Akira <akr@fsij.org>
|
||||
|
||||
* re.c (rb_reg_s_union_m): Regexp.union accepts single argument which
|
||||
is an array of patterns.
|
||||
|
||||
Fri Oct 5 16:42:27 2007 Tanaka Akira <akr@fsij.org>
|
||||
|
||||
* bootstraptest/runner.rb (assert_not_match): new method.
|
||||
|
|
30
re.c
30
re.c
|
@ -2042,21 +2042,24 @@ rb_reg_s_try_convert(VALUE dummy, VALUE re)
|
|||
|
||||
/*
|
||||
* call-seq:
|
||||
* Regexp.union([pattern]*) => new_str
|
||||
* Regexp.union([pattern]*) => new_regexp
|
||||
* Regexp.union(array_of_patterns) => new_regexp
|
||||
*
|
||||
* Return a <code>Regexp</code> object that is the union of the given
|
||||
* <em>pattern</em>s, i.e., will match any of its parts. The <em>pattern</em>s
|
||||
* can be Regexp objects, in which case their options will be preserved, or
|
||||
* Strings. If no arguments are given, returns <code>/(?!)/</code>.
|
||||
* Strings. If no patterns are given, returns <code>/(?!)/</code>.
|
||||
*
|
||||
* Regexp.union #=> /(?!)/
|
||||
* Regexp.union("penzance") #=> /penzance/
|
||||
* Regexp.union("a+b*c") #=> /a\+b\*c/
|
||||
* Regexp.union("skiing", "sledding") #=> /skiing|sledding/
|
||||
* Regexp.union(/dogs/, /cats/i) #=> /(?-mix:dogs)|(?i-mx:cats)/
|
||||
*/
|
||||
static VALUE
|
||||
rb_reg_s_union(int argc, VALUE *argv)
|
||||
rb_reg_s_union(VALUE self, VALUE args0)
|
||||
{
|
||||
long argc = RARRAY_LEN(args0);
|
||||
if (argc == 0) {
|
||||
VALUE args[1];
|
||||
args[0] = rb_str_new2("(?!)");
|
||||
|
@ -2064,12 +2067,12 @@ rb_reg_s_union(int argc, VALUE *argv)
|
|||
}
|
||||
else if (argc == 1) {
|
||||
VALUE v;
|
||||
v = rb_check_regexp_type(argv[0]);
|
||||
v = rb_check_regexp_type(rb_ary_entry(args0, 0));
|
||||
if (!NIL_P(v))
|
||||
return v;
|
||||
else {
|
||||
VALUE args[1];
|
||||
args[0] = rb_reg_s_quote(argc, argv);
|
||||
args[0] = rb_reg_s_quote(RARRAY_LEN(args0), RARRAY_PTR(args0));
|
||||
return rb_class_new_instance(1, args, rb_cRegexp);
|
||||
}
|
||||
}
|
||||
|
@ -2082,7 +2085,7 @@ rb_reg_s_union(int argc, VALUE *argv)
|
|||
volatile VALUE v;
|
||||
if (0 < i)
|
||||
rb_str_buf_cat2(source, "|");
|
||||
v = rb_check_regexp_type(argv[i]);
|
||||
v = rb_check_regexp_type(rb_ary_entry(args0, i));
|
||||
if (!NIL_P(v)) {
|
||||
if (FL_TEST(v, KCODE_FIXED)) {
|
||||
if (kcode == -1) {
|
||||
|
@ -2100,7 +2103,7 @@ rb_reg_s_union(int argc, VALUE *argv)
|
|||
v = rb_reg_to_s(v);
|
||||
}
|
||||
else {
|
||||
args[0] = argv[i];
|
||||
args[0] = rb_ary_entry(args0, i);
|
||||
v = rb_reg_s_quote(1, args);
|
||||
}
|
||||
rb_str_buf_append(source, v);
|
||||
|
@ -2117,6 +2120,17 @@ rb_reg_s_union(int argc, VALUE *argv)
|
|||
}
|
||||
}
|
||||
|
||||
static VALUE
|
||||
rb_reg_s_union_m(VALUE self, VALUE args)
|
||||
{
|
||||
VALUE v;
|
||||
if (RARRAY_LEN(args) == 1 &&
|
||||
!NIL_P(v = rb_check_array_type(rb_ary_entry(args, 0)))) {
|
||||
return rb_reg_s_union(self, v);
|
||||
}
|
||||
return rb_reg_s_union(self, args);
|
||||
}
|
||||
|
||||
/* :nodoc: */
|
||||
static VALUE
|
||||
rb_reg_init_copy(VALUE copy, VALUE re)
|
||||
|
@ -2416,7 +2430,7 @@ Init_Regexp(void)
|
|||
rb_define_singleton_method(rb_cRegexp, "compile", rb_class_new_instance, -1);
|
||||
rb_define_singleton_method(rb_cRegexp, "quote", rb_reg_s_quote, -1);
|
||||
rb_define_singleton_method(rb_cRegexp, "escape", rb_reg_s_quote, -1);
|
||||
rb_define_singleton_method(rb_cRegexp, "union", rb_reg_s_union, -1);
|
||||
rb_define_singleton_method(rb_cRegexp, "union", rb_reg_s_union_m, -2);
|
||||
rb_define_singleton_method(rb_cRegexp, "last_match", rb_reg_s_last_match, -1);
|
||||
rb_define_singleton_method(rb_cRegexp, "try_convert", rb_reg_s_try_convert, 1);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue