summaryrefslogtreecommitdiff
path: root/re.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-02-14 04:57:25 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-02-14 04:57:25 +0000
commit3098d80818c9fbaa3b5ae392f7fad319e7a65323 (patch)
treed1529e27a49d21e0d58175afae89df34ddec1dc7 /re.c
parentf2586498f3bb38310f039e7532c034011e2aef82 (diff)
* re.c (reg_operand): allow symbols to be operands for regular
expression matches. * string.c (Init_String): allow Symbol#===. * lib/date/format.rb (Date::Format::Bag::to_hash): string added prefixes. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11723 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 're.c')
-rw-r--r--re.c31
1 files changed, 22 insertions, 9 deletions
diff --git a/re.c b/re.c
index 1a01490e5b..b06e229fe9 100644
--- a/re.c
+++ b/re.c
@@ -1586,13 +1586,29 @@ rb_reg_equal(VALUE re1, VALUE re2)
}
static VALUE
+reg_operand(VALUE s, int check)
+{
+ if (SYMBOL_P(s)) {
+ return rb_sym_to_s(s);
+ }
+ else {
+ VALUE tmp = rb_check_string_type(s);
+ if (check && NIL_P(tmp)) {
+ rb_raise(rb_eTypeError, "can't convert %s to String",
+ rb_obj_classname(s));
+ }
+ return tmp;
+ }
+}
+
+static VALUE
rb_reg_match_pos(VALUE re, VALUE str, long pos)
{
if (NIL_P(str)) {
rb_backref_set(Qnil);
return Qnil;
}
- StringValue(str);
+ str = reg_operand(str, Qtrue);
if (pos != 0) {
if (pos < 0) {
pos += RSTRING_LEN(str);
@@ -1647,14 +1663,11 @@ rb_reg_eqq(VALUE re, VALUE str)
{
long start;
- if (TYPE(str) != T_STRING) {
- str = rb_check_string_type(str);
- if (NIL_P(str)) {
- rb_backref_set(Qnil);
- return Qfalse;
- }
+ str = reg_operand(str, Qfalse);
+ if (NIL_P(str)) {
+ rb_backref_set(Qnil);
+ return Qfalse;
}
- StringValue(str);
start = rb_reg_search(re, str, 0, 0);
if (start < 0) {
return Qfalse;
@@ -1912,7 +1925,7 @@ rb_reg_s_quote(int argc, VALUE *argv)
curr_kcode = reg_kcode;
reg_kcode = kcode_saved;
}
- StringValue(str);
+ str = reg_operand(str, Qtrue);
str = rb_reg_quote(str);
kcode_reset_option();
return str;