1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* 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
This commit is contained in:
nobu 2002-12-19 15:21:01 +00:00
parent 32145b0652
commit 5f4f0807e9
2 changed files with 15 additions and 7 deletions

View file

@ -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.

16
re.c
View file

@ -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);
}