diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-02-14 04:57:25 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-02-14 04:57:25 +0000 |
commit | 3098d80818c9fbaa3b5ae392f7fad319e7a65323 (patch) | |
tree | d1529e27a49d21e0d58175afae89df34ddec1dc7 | |
parent | f2586498f3bb38310f039e7532c034011e2aef82 (diff) | |
download | ruby-3098d80818c9fbaa3b5ae392f7fad319e7a65323.tar.gz |
* 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
-rw-r--r-- | ChangeLog | 10 | ||||
-rw-r--r-- | lib/date/format.rb | 4 | ||||
-rw-r--r-- | re.c | 31 | ||||
-rw-r--r-- | string.c | 8 |
4 files changed, 42 insertions, 11 deletions
@@ -1,3 +1,13 @@ +Wed Feb 14 13:12:06 2007 Yukihiro Matsumoto <matz@ruby-lang.org> + + * 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. + Wed Feb 14 12:58:38 2007 Koichi Sasada <ko1@atdot.net> * thread.c (do_select): fix to iterate select(). diff --git a/lib/date/format.rb b/lib/date/format.rb index 152ca2ff6b..0a4869e3a1 100644 --- a/lib/date/format.rb +++ b/lib/date/format.rb @@ -111,8 +111,8 @@ class Date def to_hash instance_variables. - select{|n| !instance_variable_get(n).nil?}.grep(/\A@[^_]/). - inject({}){|r, n| r[n[1..-1].intern] = instance_variable_get(n); r} + select{|n| !instance_variable_get(n).nil?}.grep(/\A@v[^_]/). + inject({}){|r, n| r[n[2..-1].intern] = instance_variable_get(n); r} end end @@ -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; @@ -4810,6 +4810,13 @@ sym_match(VALUE sym, VALUE other) } static VALUE +sym_eqq(VALUE sym, VALUE other) +{ + if (sym == other) return Qtrue; + return rb_str_equal(rb_sym_to_s(sym), other); +} + +static VALUE sym_aref(int argc, VALUE *argv, VALUE sym) { return rb_str_aref_m(argc, argv, rb_sym_to_s(sym)); @@ -5051,6 +5058,7 @@ Init_String(void) rb_define_method(rb_cSymbol, "<=>", sym_cmp, 1); rb_define_method(rb_cSymbol, "casecmp", sym_casecmp, 1); rb_define_method(rb_cSymbol, "=~", sym_match, 1); + rb_define_method(rb_cSymbol, "===", sym_eqq, 1); rb_define_method(rb_cSymbol, "[]", sym_aref, -1); rb_define_method(rb_cSymbol, "slice", sym_aref, -1); |