1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* string.c (get_pat): Add an extra argument "quote".

* string.c (rb_str_match_m): Do not bother to convert if a regexp
  is given.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2844 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
knu 2002-09-11 04:05:36 +00:00
parent 0eb196f281
commit b9e3aa30f7
2 changed files with 26 additions and 17 deletions

View file

@ -1,3 +1,10 @@
Wed Sep 11 12:58:57 2002 Akinori MUSHA <knu@iDaemons.org>
* string.c (get_pat): Add an extra argument "quote".
* string.c (rb_str_match_m): Do not bother to convert if a regexp
is given.
Wed Sep 11 11:33:40 2002 NAKAMURA Usaku <usa@ruby-lang.org>
* bcc32/Makefile.sub: remove unnecessary `.dll' from filename of

View file

@ -986,17 +986,13 @@ rb_str_match2(str)
return rb_reg_match2(rb_reg_regcomp(rb_reg_quote(str)));
}
static VALUE get_pat _((VALUE, int));
static VALUE
rb_str_match_m(str, re)
VALUE str, re;
{
VALUE str2 = rb_check_convert_type(re, T_STRING, "String", "to_str");
if (!NIL_P(str2)) {
StringValue(re);
re = rb_reg_regcomp(rb_reg_quote(re));
}
return rb_funcall(re, rb_intern("match"), 1, str);
return rb_funcall(get_pat(re, 0), rb_intern("match"), 1, str);
}
static char
@ -1380,8 +1376,9 @@ rb_str_slice_bang(argc, argv, str)
}
static VALUE
get_pat(pat)
get_pat(pat, quote)
VALUE pat;
int quote;
{
VALUE val;
@ -1399,13 +1396,18 @@ get_pat(pat)
}
pat = val;
}
val = rb_reg_quote(pat);
if (quote) {
val = rb_reg_quote(pat);
#if RUBY_VERSION_CODE < 180
if (val != pat && rb_str_cmp(val, pat) != 0) {
rb_warn("string pattern instead of regexp; metacharacters no longer effective");
}
if (val != pat && rb_str_cmp(val, pat) != 0) {
rb_warn("string pattern instead of regexp; metacharacters no longer effective");
}
#endif
return rb_reg_regcomp(val);
pat = val;
}
return rb_reg_regcomp(pat);
}
static VALUE
@ -1432,7 +1434,7 @@ rb_str_sub_bang(argc, argv, str)
rb_raise(rb_eArgError, "wrong number of arguments(%d for 2)", argc);
}
pat = get_pat(argv[0]);
pat = get_pat(argv[0], 1);
if (rb_reg_search(pat, str, 0, 0) >= 0) {
rb_str_modify(str);
match = rb_backref_get();
@ -1505,7 +1507,7 @@ str_gsub(argc, argv, str, bang)
rb_raise(rb_eArgError, "wrong number of arguments(%d for 2)", argc);
}
pat = get_pat(argv[0]);
pat = get_pat(argv[0], 1);
offset=0; n=0;
beg = rb_reg_search(pat, str, 0, 0);
if (beg < 0) {
@ -2477,7 +2479,7 @@ rb_str_split_m(argc, argv, str)
}
}
else {
spat = get_pat(spat);
spat = get_pat(spat, 1);
}
}
@ -2928,7 +2930,7 @@ rb_str_scan(str, pat)
long start = 0;
VALUE match = Qnil;
pat = get_pat(pat);
pat = get_pat(pat, 1);
if (!rb_block_given_p()) {
VALUE ary = rb_ary_new();