summaryrefslogtreecommitdiff
path: root/re.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-08-27 08:31:08 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-08-27 08:31:08 +0000
commitc45908e41f47c88674b73a754ecd0535449b667a (patch)
treea27bb0f2ca80fa80b9582ddcb8312eee673b0bd5 /re.c
parentcd3d4a01f248fad1a73ff0b66b7a8d1653f64c19 (diff)
* file.c (rb_find_file): $LOAD_PATH must not be empty.
* file.c (rb_find_file_ext): ditto. * range.c (range_eq): class check should be based on range.class, instead of Range to work with Range.dup. * range.c (range_eql): ditto. * class.c (rb_mod_dup): need to preserve metaclass and flags. * object.c (rb_cstr_to_dbl): had a buffer overrun. * marshal.c (w_class): integrate singleton check into a funciton to follow DRY principle. * marshal.c (w_uclass): should check singleton method. * object.c (rb_obj_dup): dmark and dfree functions must be match for T_DATA type. * object.c (rb_obj_dup): class of the duped object must be match to the class of the original. * re.c (rb_reg_quote): do not escape \t, \f, \r, \n, for they are not regular expression metacharacters. * time.c (time_s_alloc): use time_free instead of free (null check, also serves for type mark). * time.c (time_s_at): check dfree function too. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2748 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 're.c')
-rw-r--r--re.c47
1 files changed, 26 insertions, 21 deletions
diff --git a/re.c b/re.c
index a8e4cc3b0b..87c06d675d 100644
--- a/re.c
+++ b/re.c
@@ -545,6 +545,23 @@ match_clone(match)
}
static VALUE
+match_dup(match)
+ VALUE match;
+{
+ NEWOBJ(dup, struct RMatch);
+ DUPSETUP(dup, match);
+
+ dup->str = RMATCH(match)->str;
+ dup->regs = 0;
+
+ dup->regs = ALLOC(struct re_registers);
+ dup->regs->allocated = 0;
+ re_copy_registers(dup->regs, RMATCH(match)->regs);
+
+ return (VALUE)dup;
+}
+
+static VALUE
match_size(match)
VALUE match;
{
@@ -1195,7 +1212,6 @@ rb_reg_quote(str)
continue;
}
switch (c) {
- case '\t': case '\f': case '\r': case '\n':
case '[': case ']': case '{': case '}':
case '(': case ')': case '|': case '-':
case '*': case '.': case '\\':
@@ -1224,22 +1240,6 @@ rb_reg_quote(str)
continue;
}
switch (c) {
- case '\t':
- c = 't';
- *t++ = '\\';
- break;
- case '\f':
- c = 'f';
- *t++ = '\\';
- break;
- case '\r':
- c = 'r';
- *t++ = '\\';
- break;
- case '\n':
- c = 'n';
- *t++ = '\\';
- break;
case '[': case ']': case '{': case '}':
case '(': case ')': case '|': case '-':
case '*': case '.': case '\\':
@@ -1329,11 +1329,13 @@ rb_reg_options(re)
}
static VALUE
-rb_reg_clone(re)
+rb_reg_become(clone, re)
VALUE re;
{
- VALUE clone = rb_obj_clone(re);
-
+ /* need better argument type check */
+ if (!rb_obj_is_kind_of(re, rb_obj_class(clone))) {
+ rb_raise(rb_eTypeError, "wrong argument type");
+ }
RREGEXP(clone)->ptr = 0;
RREGEXP(clone)->len = 0;
RREGEXP(clone)->str = 0;
@@ -1578,7 +1580,7 @@ Init_Regexp()
rb_define_singleton_method(rb_cRegexp, "last_match", rb_reg_s_last_match, -1);
rb_define_method(rb_cRegexp, "initialize", rb_reg_initialize_m, -1);
- rb_define_method(rb_cRegexp, "clone", rb_reg_clone, 0);
+ rb_define_method(rb_cRegexp, "become", rb_reg_become, 1);
rb_define_method(rb_cRegexp, "==", rb_reg_equal, 1);
rb_define_method(rb_cRegexp, "=~", rb_reg_match, 1);
rb_define_method(rb_cRegexp, "===", rb_reg_match, 1);
@@ -1602,7 +1604,10 @@ Init_Regexp()
rb_undef_method(CLASS_OF(rb_cMatch), "allocate");
rb_undef_method(CLASS_OF(rb_cMatch), "new");
+ /* to be replaced by allocation framework */
rb_define_method(rb_cMatch, "clone", match_clone, 0);
+ rb_define_method(rb_cMatch, "dup", match_dup, 0);
+
rb_define_method(rb_cMatch, "size", match_size, 0);
rb_define_method(rb_cMatch, "length", match_size, 0);
rb_define_method(rb_cMatch, "offset", match_offset, 1);