summaryrefslogtreecommitdiff
path: root/re.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2001-10-03 07:19:19 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2001-10-03 07:19:19 +0000
commit1fe40b7cc5e92105f636d670d77b059fe4a4c50b (patch)
tree02dfc7bab198fc494d9d4f1f3bf1072d292fed66 /re.c
parentd902111a57dfcf3c9b017b0ebd1b49f19142168c (diff)
* marshal.c (r_object): better allocation type check for
TYPE_UCLASS. usage of allocation framework is disabled for now. * variable.c (rb_class_path): Module may have subclass. * string.c (rb_str_update): should maintain original negative offset. * string.c (rb_str_subpat_set): ditto * string.c (rb_str_aset): ditto. * re.c (rb_reg_nth_match): should check negative nth. * re.c (rb_reg_nth_defined): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@1764 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 're.c')
-rw-r--r--re.c42
1 files changed, 27 insertions, 15 deletions
diff --git a/re.c b/re.c
index 7029283..06a4b39 100644
--- a/re.c
+++ b/re.c
@@ -665,7 +665,11 @@ rb_reg_nth_defined(nth, match)
{
if (NIL_P(match)) return Qnil;
if (nth >= RMATCH(match)->regs->num_regs) {
- return Qfalse;
+ return Qnil;
+ }
+ if (nth < 0) {
+ nth += RMATCH(match)->regs->num_regs;
+ if (nth <= 0) return Qnil;
}
if (RMATCH(match)->BEG(nth) == -1) return Qfalse;
return Qtrue;
@@ -683,6 +687,10 @@ rb_reg_nth_match(nth, match)
if (nth >= RMATCH(match)->regs->num_regs) {
return Qnil;
}
+ if (nth < 0) {
+ nth += RMATCH(match)->regs->num_regs;
+ if (nth <= 0) return Qnil;
+ }
start = RMATCH(match)->BEG(nth);
if (start == -1) return Qnil;
end = RMATCH(match)->END(nth);
@@ -881,6 +889,7 @@ rb_reg_new(s, len, options)
long len;
int options;
{
+
NEWOBJ(re, struct RRegexp);
OBJSETUP(re, rb_cRegexp, T_REGEXP);
@@ -1033,16 +1042,16 @@ rb_reg_initialize_m(argc, argv, self)
}
static VALUE
-rb_reg_s_new(argc, argv, klass)
- int argc;
- VALUE *argv;
+rb_reg_s_alloc(klass)
VALUE klass;
{
- NEWOBJ(re, struct RRegexp);
- OBJSETUP(re, klass, T_REGEXP);
- re->ptr = 0; re->len = 0; re->str = 0;
- rb_obj_call_init((VALUE)re, argc, argv);
- return (VALUE)re;
+ VALUE re = rb_obj_alloc(klass);
+
+ RREGEXP(re)->ptr = 0;
+ RREGEXP(re)->len = 0;
+ RREGEXP(re)->str = 0;
+
+ return re;
}
static VALUE
@@ -1152,13 +1161,15 @@ static VALUE
rb_reg_clone(re)
VALUE re;
{
- NEWOBJ(clone, struct RRegexp);
- CLONESETUP(clone, re);
+ VALUE clone = rb_obj_clone(re);
+
+ RREGEXP(clone)->ptr = 0;
+ RREGEXP(clone)->len = 0;
+ RREGEXP(clone)->str = 0;
rb_reg_check(re);
- clone->ptr = 0; clone->len = 0; clone->str = 0;
rb_reg_initialize(clone, RREGEXP(re)->str, RREGEXP(re)->len,
rb_reg_options(re));
- return (VALUE)re;
+ return clone;
}
VALUE
@@ -1387,8 +1398,8 @@ Init_Regexp()
rb_define_virtual_variable("$-K", kcode_getter, kcode_setter);
rb_cRegexp = rb_define_class("Regexp", rb_cObject);
- rb_define_singleton_method(rb_cRegexp, "new", rb_reg_s_new, -1);
- rb_define_singleton_method(rb_cRegexp, "compile", rb_reg_s_new, -1);
+ rb_define_singleton_method(rb_cRegexp, "allocate", rb_reg_s_alloc, 0);
+ rb_define_singleton_method(rb_cRegexp, "compile", rb_class_new_instance, -1);
rb_define_singleton_method(rb_cRegexp, "quote", rb_reg_s_quote, -1);
rb_define_singleton_method(rb_cRegexp, "escape", rb_reg_s_quote, -1);
rb_define_singleton_method(rb_cRegexp, "last_match", rb_reg_s_last_match, -1);
@@ -1415,6 +1426,7 @@ Init_Regexp()
rb_cMatch = rb_define_class("MatchData", rb_cObject);
rb_define_global_const("MatchingData", rb_cMatch);
+ rb_undef_method(CLASS_OF(rb_cMatch), "allocate");
rb_undef_method(CLASS_OF(rb_cMatch), "new");
rb_define_method(rb_cMatch, "clone", match_clone, 0);