summaryrefslogtreecommitdiff
path: root/re.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-02-03 08:45:26 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-02-03 08:45:26 +0000
commit467035750e83a2d532bd8c2c5fb9fd78c1810132 (patch)
tree99b881e01316af946a2dfa978b0067aae9675f6b /re.c
parent056585d6dc58c4b9b1e4bf5e58c0bc81b5122fc6 (diff)
* 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
Diffstat (limited to 're.c')
-rw-r--r--re.c65
1 files changed, 43 insertions, 22 deletions
diff --git a/re.c b/re.c
index dbf9bdf..9b78681 100644
--- a/re.c
+++ b/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;
}