зеркало из https://github.com/github/ruby.git
* 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
This commit is contained in:
Родитель
f2586498f3
Коммит
3098d80818
10
ChangeLog
10
ChangeLog
|
@ -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>
|
Wed Feb 14 12:58:38 2007 Koichi Sasada <ko1@atdot.net>
|
||||||
|
|
||||||
* thread.c (do_select): fix to iterate select().
|
* thread.c (do_select): fix to iterate select().
|
||||||
|
|
|
@ -111,8 +111,8 @@ class Date
|
||||||
|
|
||||||
def to_hash
|
def to_hash
|
||||||
instance_variables.
|
instance_variables.
|
||||||
select{|n| !instance_variable_get(n).nil?}.grep(/\A@[^_]/).
|
select{|n| !instance_variable_get(n).nil?}.grep(/\A@v[^_]/).
|
||||||
inject({}){|r, n| r[n[1..-1].intern] = instance_variable_get(n); r}
|
inject({}){|r, n| r[n[2..-1].intern] = instance_variable_get(n); r}
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
31
re.c
31
re.c
|
@ -1585,6 +1585,22 @@ rb_reg_equal(VALUE re1, VALUE re2)
|
||||||
return Qfalse;
|
return Qfalse;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
static VALUE
|
||||||
rb_reg_match_pos(VALUE re, VALUE str, long pos)
|
rb_reg_match_pos(VALUE re, VALUE str, long pos)
|
||||||
{
|
{
|
||||||
|
@ -1592,7 +1608,7 @@ rb_reg_match_pos(VALUE re, VALUE str, long pos)
|
||||||
rb_backref_set(Qnil);
|
rb_backref_set(Qnil);
|
||||||
return Qnil;
|
return Qnil;
|
||||||
}
|
}
|
||||||
StringValue(str);
|
str = reg_operand(str, Qtrue);
|
||||||
if (pos != 0) {
|
if (pos != 0) {
|
||||||
if (pos < 0) {
|
if (pos < 0) {
|
||||||
pos += RSTRING_LEN(str);
|
pos += RSTRING_LEN(str);
|
||||||
|
@ -1647,14 +1663,11 @@ rb_reg_eqq(VALUE re, VALUE str)
|
||||||
{
|
{
|
||||||
long start;
|
long start;
|
||||||
|
|
||||||
if (TYPE(str) != T_STRING) {
|
str = reg_operand(str, Qfalse);
|
||||||
str = rb_check_string_type(str);
|
if (NIL_P(str)) {
|
||||||
if (NIL_P(str)) {
|
rb_backref_set(Qnil);
|
||||||
rb_backref_set(Qnil);
|
return Qfalse;
|
||||||
return Qfalse;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
StringValue(str);
|
|
||||||
start = rb_reg_search(re, str, 0, 0);
|
start = rb_reg_search(re, str, 0, 0);
|
||||||
if (start < 0) {
|
if (start < 0) {
|
||||||
return Qfalse;
|
return Qfalse;
|
||||||
|
@ -1912,7 +1925,7 @@ rb_reg_s_quote(int argc, VALUE *argv)
|
||||||
curr_kcode = reg_kcode;
|
curr_kcode = reg_kcode;
|
||||||
reg_kcode = kcode_saved;
|
reg_kcode = kcode_saved;
|
||||||
}
|
}
|
||||||
StringValue(str);
|
str = reg_operand(str, Qtrue);
|
||||||
str = rb_reg_quote(str);
|
str = rb_reg_quote(str);
|
||||||
kcode_reset_option();
|
kcode_reset_option();
|
||||||
return str;
|
return str;
|
||||||
|
|
8
string.c
8
string.c
|
@ -4809,6 +4809,13 @@ sym_match(VALUE sym, VALUE other)
|
||||||
return rb_str_match(rb_sym_to_s(sym), other);
|
return rb_str_match(rb_sym_to_s(sym), 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
|
static VALUE
|
||||||
sym_aref(int argc, VALUE *argv, VALUE sym)
|
sym_aref(int argc, VALUE *argv, VALUE sym)
|
||||||
{
|
{
|
||||||
|
@ -5051,6 +5058,7 @@ Init_String(void)
|
||||||
rb_define_method(rb_cSymbol, "<=>", sym_cmp, 1);
|
rb_define_method(rb_cSymbol, "<=>", sym_cmp, 1);
|
||||||
rb_define_method(rb_cSymbol, "casecmp", sym_casecmp, 1);
|
rb_define_method(rb_cSymbol, "casecmp", sym_casecmp, 1);
|
||||||
rb_define_method(rb_cSymbol, "=~", sym_match, 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, "[]", sym_aref, -1);
|
||||||
rb_define_method(rb_cSymbol, "slice", sym_aref, -1);
|
rb_define_method(rb_cSymbol, "slice", sym_aref, -1);
|
||||||
|
|
Загрузка…
Ссылка в новой задаче