summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-12-19 15:21:01 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-12-19 15:21:01 +0000
commit5f4f0807e90ad9513333a68836e9dfcf01e9df48 (patch)
tree001709f4e7a8cf1863907bd45f2a839bff6455d2
parent32145b065247829d30ddad2616f796625ca37d9c (diff)
* re.c (rb_reg_match_pre, rb_reg_match_post, match_to_a,
match_select): return instances of same class as the original string. [ruby-dev:19119] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3175 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog6
-rw-r--r--re.c16
2 files changed, 15 insertions, 7 deletions
diff --git a/ChangeLog b/ChangeLog
index 8b5b12cc4b..8e5ccaa48d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Fri Dec 20 00:16:06 2002 Nobuyoshi Nakada <nobu.nokada@softhome.net>
+
+ * re.c (rb_reg_match_pre, rb_reg_match_post, match_to_a,
+ match_select): return instances of same class as the original
+ string. [ruby-dev:19119]
+
Thu Dec 19 22:55:49 2002 NAKAMURA Usaku <usa@ruby-lang.org>
* numeric.c (DBL_EPSILON): fix typo.
diff --git a/re.c b/re.c
index 0035f24624..354bab28e1 100644
--- a/re.c
+++ b/re.c
@@ -798,7 +798,7 @@ rb_reg_match_pre(match)
if (NIL_P(match)) return Qnil;
if (RMATCH(match)->BEG(0) == -1) return Qnil;
- str = rb_str_new(RSTRING(RMATCH(match)->str)->ptr, RMATCH(match)->BEG(0));
+ str = rb_str_substr(RMATCH(match)->str, 0, RMATCH(match)->BEG(0));
if (OBJ_TAINTED(match)) OBJ_TAINT(str);
return str;
}
@@ -808,11 +808,13 @@ rb_reg_match_post(match)
VALUE match;
{
VALUE str;
+ long pos;
if (NIL_P(match)) return Qnil;
if (RMATCH(match)->BEG(0) == -1) return Qnil;
- str = rb_str_new(RSTRING(RMATCH(match)->str)->ptr+RMATCH(match)->END(0),
- RSTRING(RMATCH(match)->str)->len-RMATCH(match)->END(0));
+ str = RMATCH(match)->str;
+ pos = RMATCH(match)->END(0);
+ str = rb_str_substr(str, pos, RSTRING(str)->len - pos);
if (OBJ_TAINTED(match)) OBJ_TAINT(str);
return str;
}
@@ -862,7 +864,7 @@ match_to_a(match)
{
struct re_registers *regs = RMATCH(match)->regs;
VALUE ary = rb_ary_new2(regs->num_regs);
- char *ptr = RSTRING(RMATCH(match)->str)->ptr;
+ VALUE target = RMATCH(match)->str;
int i;
int taint = OBJ_TAINTED(match);
@@ -871,7 +873,7 @@ match_to_a(match)
rb_ary_push(ary, Qnil);
}
else {
- VALUE str = rb_str_new(ptr+regs->beg[i], regs->end[i]-regs->beg[i]);
+ VALUE str = rb_str_substr(target, regs->beg[i], regs->end[i]-regs->beg[i]);
if (taint) OBJ_TAINT(str);
rb_ary_push(ary, str);
}
@@ -902,7 +904,7 @@ match_select(argc, argv, match)
VALUE match;
{
struct re_registers *regs = RMATCH(match)->regs;
- char *ptr = RSTRING(RMATCH(match)->str)->ptr;
+ VALUE target = RMATCH(match)->str;
VALUE result = rb_ary_new();
int i;
long idx;
@@ -915,7 +917,7 @@ match_select(argc, argv, match)
rb_ary_push(result, Qnil);
}
else {
- VALUE str = rb_str_new(ptr+regs->beg[idx], regs->end[idx]-regs->beg[idx]);
+ VALUE str = rb_str_substr(target, regs->beg[idx], regs->end[idx]-regs->beg[idx]);
if (taint) OBJ_TAINT(str);
rb_ary_push(result, str);
}