summaryrefslogtreecommitdiff
path: root/string.c
diff options
context:
space:
mode:
authorknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-09-11 04:05:36 +0000
committerknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-09-11 04:05:36 +0000
commitb9e3aa30f78a7734273c83748841776fec2ba7be (patch)
treeba4bae891b306f09555bbb3d64c8e945a3b101b7 /string.c
parent0eb196f281259b77efe550044c05a213122a2b91 (diff)
* 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
Diffstat (limited to 'string.c')
-rw-r--r--string.c36
1 files changed, 19 insertions, 17 deletions
diff --git a/string.c b/string.c
index 6bd42f0..3149ad7 100644
--- a/string.c
+++ b/string.c
@@ -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();