mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* object.c (Init_Object): default Object#=== now calls "=="
internally. * re.c (rb_reg_initialize_m): should honor option status of original regexp. * array.c (rb_ary_equal): ary2 should be T_ARRAY (no to_ary conversion). * array.c (rb_ary_eql): ditto. * string.c (rb_str_equal): str2 should be T_STRING (no to_str conversion). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3435 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
056585d6dc
commit
467035750e
6 changed files with 65 additions and 41 deletions
16
ChangeLog
16
ChangeLog
|
@ -1,3 +1,19 @@
|
|||
Mon Feb 3 16:49:19 2003 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||
|
||||
* object.c (Init_Object): default Object#=== now calls "=="
|
||||
internally.
|
||||
|
||||
* re.c (rb_reg_initialize_m): should honor option status of
|
||||
original regexp.
|
||||
|
||||
* array.c (rb_ary_equal): ary2 should be T_ARRAY (no to_ary
|
||||
conversion).
|
||||
|
||||
* array.c (rb_ary_eql): ditto.
|
||||
|
||||
* string.c (rb_str_equal): str2 should be T_STRING (no to_str
|
||||
conversion).
|
||||
|
||||
Mon Feb 3 16:32:52 2003 Nobuyoshi Nakada <nobu.nokada@softhome.net>
|
||||
|
||||
* re.c (rb_memsearch): a little improvement.
|
||||
|
|
11
array.c
11
array.c
|
@ -1563,10 +1563,7 @@ rb_ary_equal(ary1, ary2)
|
|||
long i;
|
||||
|
||||
if (ary1 == ary2) return Qtrue;
|
||||
if (TYPE(ary2) != T_ARRAY) {
|
||||
ary2 = rb_check_array_type(ary2);
|
||||
if (NIL_P(ary2)) return Qfalse;
|
||||
}
|
||||
if (TYPE(ary2) != T_ARRAY) return Qfalse;
|
||||
if (RARRAY(ary1)->len != RARRAY(ary2)->len) return Qfalse;
|
||||
for (i=0; i<RARRAY(ary1)->len; i++) {
|
||||
if (!rb_equal(RARRAY(ary1)->ptr[i], RARRAY(ary2)->ptr[i]))
|
||||
|
@ -1582,10 +1579,7 @@ rb_ary_eql(ary1, ary2)
|
|||
long i;
|
||||
|
||||
if (ary1 == ary2) return Qtrue;
|
||||
if (TYPE(ary2) != T_ARRAY) {
|
||||
ary2 = rb_check_array_type(ary2);
|
||||
if (NIL_P(ary2)) return Qfalse;
|
||||
}
|
||||
if (TYPE(ary2) != T_ARRAY) return Qfalse;
|
||||
if (RARRAY(ary1)->len != RARRAY(ary2)->len) return Qfalse;
|
||||
for (i=0; i<RARRAY(ary1)->len; i++) {
|
||||
if (!rb_eql(RARRAY(ary1)->ptr[i], RARRAY(ary2)->ptr[i]))
|
||||
|
@ -1898,7 +1892,6 @@ Init_Array()
|
|||
rb_define_method(rb_cArray, "==", rb_ary_equal, 1);
|
||||
rb_define_method(rb_cArray, "eql?", rb_ary_eql, 1);
|
||||
rb_define_method(rb_cArray, "hash", rb_ary_hash, 0);
|
||||
rb_define_method(rb_cArray, "===", rb_ary_equal, 1);
|
||||
|
||||
rb_define_method(rb_cArray, "[]", rb_ary_aref, -1);
|
||||
rb_define_method(rb_cArray, "[]=", rb_ary_aset, -1);
|
||||
|
|
|
@ -1723,7 +1723,6 @@ Init_Numeric()
|
|||
|
||||
rb_define_method(rb_cNumeric, "+@", num_uplus, 0);
|
||||
rb_define_method(rb_cNumeric, "-@", num_uminus, 0);
|
||||
rb_define_method(rb_cNumeric, "===", num_equal, 1);
|
||||
rb_define_method(rb_cNumeric, "<=>", num_cmp, 1);
|
||||
rb_define_method(rb_cNumeric, "eql?", num_eql, 1);
|
||||
rb_define_method(rb_cNumeric, "quo", num_quo, 1);
|
||||
|
|
2
object.c
2
object.c
|
@ -1314,7 +1314,7 @@ Init_Object()
|
|||
rb_define_method(rb_mKernel, "nil?", rb_false, 0);
|
||||
rb_define_method(rb_mKernel, "==", rb_obj_equal, 1);
|
||||
rb_define_method(rb_mKernel, "equal?", rb_obj_equal, 1);
|
||||
rb_define_method(rb_mKernel, "===", rb_obj_equal, 1);
|
||||
rb_define_method(rb_mKernel, "===", rb_equal, 1);
|
||||
rb_define_method(rb_mKernel, "=~", rb_false, 1);
|
||||
|
||||
rb_define_method(rb_mKernel, "eql?", rb_obj_equal, 1);
|
||||
|
|
65
re.c
65
re.c
|
@ -1225,47 +1225,68 @@ rb_reg_initialize_m(argc, argv, self)
|
|||
VALUE *argv;
|
||||
VALUE self;
|
||||
{
|
||||
VALUE src;
|
||||
const char *s;
|
||||
long len;
|
||||
int flags = 0;
|
||||
|
||||
rb_check_frozen(self);
|
||||
if (argc == 0 || argc > 3) {
|
||||
rb_raise(rb_eArgError, "wrong number of argument");
|
||||
}
|
||||
if (argc >= 2) {
|
||||
if (FIXNUM_P(argv[1])) flags = FIX2INT(argv[1]);
|
||||
else if (RTEST(argv[1])) flags = RE_OPTION_IGNORECASE;
|
||||
}
|
||||
if (argc == 3) {
|
||||
char *kcode = StringValuePtr(argv[2]);
|
||||
|
||||
switch (kcode[0]) {
|
||||
case 'n': case 'N':
|
||||
if (TYPE(argv[0]) == T_REGEXP) {
|
||||
if (argc > 1) {
|
||||
rb_warn("flags%s ignored", (argc == 3) ? " and encoding": "");
|
||||
}
|
||||
rb_reg_check(argv[0]);
|
||||
flags = RREGEXP(argv[0])->ptr->options & 0xf;
|
||||
switch (RBASIC(argv[0])->flags & KCODE_MASK) {
|
||||
case KCODE_NONE:
|
||||
flags |= 16;
|
||||
break;
|
||||
case 'e': case 'E':
|
||||
case KCODE_EUC:
|
||||
flags |= 32;
|
||||
break;
|
||||
case 's': case 'S':
|
||||
case KCODE_SJIS:
|
||||
flags |= 48;
|
||||
break;
|
||||
case 'u': case 'U':
|
||||
case KCODE_UTF8:
|
||||
flags |= 64;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
rb_check_frozen(self);
|
||||
src = argv[0];
|
||||
if (TYPE(src) == T_REGEXP) {
|
||||
rb_reg_check(src);
|
||||
rb_reg_initialize(self, RREGEXP(src)->str, RREGEXP(src)->len, flags);
|
||||
s = RREGEXP(argv[0])->str;
|
||||
len = RREGEXP(argv[0])->len;
|
||||
}
|
||||
else {
|
||||
StringValue(src);
|
||||
rb_reg_initialize(self, RSTRING(src)->ptr, RSTRING(src)->len, flags);
|
||||
s = StringValuePtr(argv[0]);
|
||||
len = RREGEXP(argv[0])->len;
|
||||
if (argc >= 2) {
|
||||
if (FIXNUM_P(argv[1])) flags = FIX2INT(argv[1]);
|
||||
else if (RTEST(argv[1])) flags = RE_OPTION_IGNORECASE;
|
||||
}
|
||||
else if (argc == 3) {
|
||||
char *kcode = StringValuePtr(argv[2]);
|
||||
|
||||
switch (kcode[0]) {
|
||||
case 'n': case 'N':
|
||||
flags |= 16;
|
||||
break;
|
||||
case 'e': case 'E':
|
||||
flags |= 32;
|
||||
break;
|
||||
case 's': case 'S':
|
||||
flags |= 48;
|
||||
break;
|
||||
case 'u': case 'U':
|
||||
flags |= 64;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
rb_reg_initialize(self, s, len, flags);
|
||||
return self;
|
||||
}
|
||||
|
||||
|
|
11
string.c
11
string.c
|
@ -773,13 +773,9 @@ rb_str_equal(str1, str2)
|
|||
VALUE str1, str2;
|
||||
{
|
||||
if (str1 == str2) return Qtrue;
|
||||
if (TYPE(str2) != T_STRING) {
|
||||
str2 = rb_check_string_type(str2);
|
||||
if (NIL_P(str2)) return Qfalse;
|
||||
}
|
||||
|
||||
if (RSTRING(str1)->len == RSTRING(str2)->len
|
||||
&& rb_str_cmp(str1, str2) == 0) {
|
||||
if (TYPE(str2) != T_STRING) return Qfalse;
|
||||
if (RSTRING(str1)->len == RSTRING(str2)->len &&
|
||||
rb_str_cmp(str1, str2) == 0) {
|
||||
return Qtrue;
|
||||
}
|
||||
return Qfalse;
|
||||
|
@ -3194,7 +3190,6 @@ Init_String()
|
|||
rb_define_method(rb_cString, "copy_object", rb_str_replace, 1);
|
||||
rb_define_method(rb_cString, "<=>", rb_str_cmp_m, 1);
|
||||
rb_define_method(rb_cString, "==", rb_str_equal, 1);
|
||||
rb_define_method(rb_cString, "===", rb_str_equal, 1);
|
||||
rb_define_method(rb_cString, "eql?", rb_str_eql, 1);
|
||||
rb_define_method(rb_cString, "hash", rb_str_hash_m, 0);
|
||||
rb_define_method(rb_cString, "casecmp", rb_str_casecmp, 1);
|
||||
|
|
Loading…
Reference in a new issue