* 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:
parent
0eb196f281
commit
b9e3aa30f7
@ -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>
|
Wed Sep 11 11:33:40 2002 NAKAMURA Usaku <usa@ruby-lang.org>
|
||||||
|
|
||||||
* bcc32/Makefile.sub: remove unnecessary `.dll' from filename of
|
* bcc32/Makefile.sub: remove unnecessary `.dll' from filename of
|
||||||
|
36
string.c
36
string.c
@ -986,17 +986,13 @@ rb_str_match2(str)
|
|||||||
return rb_reg_match2(rb_reg_regcomp(rb_reg_quote(str)));
|
return rb_reg_match2(rb_reg_regcomp(rb_reg_quote(str)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static VALUE get_pat _((VALUE, int));
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
rb_str_match_m(str, re)
|
rb_str_match_m(str, re)
|
||||||
VALUE str, re;
|
VALUE str, re;
|
||||||
{
|
{
|
||||||
VALUE str2 = rb_check_convert_type(re, T_STRING, "String", "to_str");
|
return rb_funcall(get_pat(re, 0), rb_intern("match"), 1, str);
|
||||||
|
|
||||||
if (!NIL_P(str2)) {
|
|
||||||
StringValue(re);
|
|
||||||
re = rb_reg_regcomp(rb_reg_quote(re));
|
|
||||||
}
|
|
||||||
return rb_funcall(re, rb_intern("match"), 1, str);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static char
|
static char
|
||||||
@ -1380,8 +1376,9 @@ rb_str_slice_bang(argc, argv, str)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
get_pat(pat)
|
get_pat(pat, quote)
|
||||||
VALUE pat;
|
VALUE pat;
|
||||||
|
int quote;
|
||||||
{
|
{
|
||||||
VALUE val;
|
VALUE val;
|
||||||
|
|
||||||
@ -1399,13 +1396,18 @@ get_pat(pat)
|
|||||||
}
|
}
|
||||||
pat = val;
|
pat = val;
|
||||||
}
|
}
|
||||||
val = rb_reg_quote(pat);
|
|
||||||
|
if (quote) {
|
||||||
|
val = rb_reg_quote(pat);
|
||||||
#if RUBY_VERSION_CODE < 180
|
#if RUBY_VERSION_CODE < 180
|
||||||
if (val != pat && rb_str_cmp(val, pat) != 0) {
|
if (val != pat && rb_str_cmp(val, pat) != 0) {
|
||||||
rb_warn("string pattern instead of regexp; metacharacters no longer effective");
|
rb_warn("string pattern instead of regexp; metacharacters no longer effective");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
return rb_reg_regcomp(val);
|
pat = val;
|
||||||
|
}
|
||||||
|
|
||||||
|
return rb_reg_regcomp(pat);
|
||||||
}
|
}
|
||||||
|
|
||||||
static VALUE
|
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);
|
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) {
|
if (rb_reg_search(pat, str, 0, 0) >= 0) {
|
||||||
rb_str_modify(str);
|
rb_str_modify(str);
|
||||||
match = rb_backref_get();
|
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);
|
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;
|
offset=0; n=0;
|
||||||
beg = rb_reg_search(pat, str, 0, 0);
|
beg = rb_reg_search(pat, str, 0, 0);
|
||||||
if (beg < 0) {
|
if (beg < 0) {
|
||||||
@ -2477,7 +2479,7 @@ rb_str_split_m(argc, argv, str)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
spat = get_pat(spat);
|
spat = get_pat(spat, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2928,7 +2930,7 @@ rb_str_scan(str, pat)
|
|||||||
long start = 0;
|
long start = 0;
|
||||||
VALUE match = Qnil;
|
VALUE match = Qnil;
|
||||||
|
|
||||||
pat = get_pat(pat);
|
pat = get_pat(pat, 1);
|
||||||
if (!rb_block_given_p()) {
|
if (!rb_block_given_p()) {
|
||||||
VALUE ary = rb_ary_new();
|
VALUE ary = rb_ary_new();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user