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

* string.c (rb_str_gsub_bang): modify check at the beginning.

[ruby-core:23662]  ref [ruby-core:23657]

* string.c (rb_str_rstrip_bang): ditto.  [ruby-core:23657]

* string.c (rb_str_chop_bang): ditto.

* string.c (rb_str_chomp_bang): ditto.

* string.c (rb_str_reverse_bang): modify check added.  [ruby-core:23671]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@23620 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 2009-06-02 15:24:23 +00:00
parent 8b362c8a23
commit c5949a0e58
2 changed files with 23 additions and 6 deletions

View file

@ -2,6 +2,19 @@ Tue Jun 2 13:27:21 2009 Kazuhiro NISHIYAMA <zn@mbf.nifty.com>
* test/ripper/test_filter.rb: add tests. see [ruby-dev:37856]
Tue Jun 2 07:44:43 2009 Yukihiro Matsumoto <matz@ruby-lang.org>
* string.c (rb_str_gsub_bang): modify check at the beginning.
[ruby-core:23662] ref [ruby-core:23657]
* string.c (rb_str_rstrip_bang): ditto. [ruby-core:23657]
* string.c (rb_str_chop_bang): ditto.
* string.c (rb_str_chomp_bang): ditto.
* string.c (rb_str_reverse_bang): modify check added. [ruby-core:23671]
Mon Jun 1 11:21:29 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
* cont.c (cont_capture, fiber_store): reraise transferred error.

View file

@ -3744,7 +3744,6 @@ str_gsub(int argc, VALUE *argv, VALUE str, int bang)
val = rb_obj_as_string(val);
}
str_mod_check(str, sp, slen);
if (bang) str_frozen_check(str);
if (val == dest) { /* paranoid check [ruby-dev:24827] */
rb_raise(rb_eRuntimeError, "block should not cheat");
}
@ -3808,6 +3807,7 @@ str_gsub(int argc, VALUE *argv, VALUE str, int bang)
static VALUE
rb_str_gsub_bang(int argc, VALUE *argv, VALUE str)
{
str_modify_keep_cr(str);
return str_gsub(argc, argv, str, 1);
}
@ -4049,6 +4049,9 @@ rb_str_reverse_bang(VALUE str)
rb_str_shared_replace(str, rb_str_reverse(str));
}
}
else {
str_modify_keep_cr(str);
}
return str;
}
@ -6044,12 +6047,15 @@ chopped_length(VALUE str)
static VALUE
rb_str_chop_bang(VALUE str)
{
str_modify_keep_cr(str);
if (RSTRING_LEN(str) > 0) {
long len;
rb_str_modify(str);
len = chopped_length(str);
STR_SET_LEN(str, len);
RSTRING_PTR(str)[len] = '\0';
if (ENC_CODERANGE(str) != ENC_CODERANGE_7BIT) {
ENC_CODERANGE_CLEAR(str);
}
return str;
}
return Qnil;
@ -6100,6 +6106,7 @@ rb_str_chomp_bang(int argc, VALUE *argv, VALUE str)
char *p, *pp, *e;
long len, rslen;
str_modify_keep_cr(str);
len = RSTRING_LEN(str);
if (len == 0) return Qnil;
p = RSTRING_PTR(str);
@ -6108,7 +6115,6 @@ rb_str_chomp_bang(int argc, VALUE *argv, VALUE str)
rs = rb_rs;
if (rs == rb_default_rs) {
smart_chomp:
str_modify_keep_cr(str);
enc = rb_enc_get(str);
if (rb_enc_mbminlen(enc) > 1) {
pp = rb_enc_left_char_head(p, e-rb_enc_mbminlen(enc), e, enc);
@ -6160,7 +6166,6 @@ rb_str_chomp_bang(int argc, VALUE *argv, VALUE str)
len--;
}
if (len < RSTRING_LEN(str)) {
str_modify_keep_cr(str);
STR_SET_LEN(str, len);
RSTRING_PTR(str)[len] = '\0';
return str;
@ -6182,7 +6187,6 @@ rb_str_chomp_bang(int argc, VALUE *argv, VALUE str)
memcmp(RSTRING_PTR(rs), pp, rslen) == 0)) {
if (rb_enc_left_char_head(p, pp, e, enc) != pp)
return Qnil;
str_modify_keep_cr(str);
if (ENC_CODERANGE(str) != ENC_CODERANGE_7BIT) {
ENC_CODERANGE_CLEAR(str);
}
@ -6301,6 +6305,7 @@ rb_str_rstrip_bang(VALUE str)
rb_encoding *enc;
char *s, *t, *e;
str_modify_keep_cr(str);
enc = STR_ENC_GET(str);
rb_str_check_dummy_enc(enc);
s = RSTRING_PTR(str);
@ -6324,7 +6329,6 @@ rb_str_rstrip_bang(VALUE str)
if (t < e) {
int len = t-RSTRING_PTR(str);
str_modify_keep_cr(str);
STR_SET_LEN(str, len);
RSTRING_PTR(str)[len] = '\0';
return str;