diff options
| author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-12-12 03:11:44 +0000 |
|---|---|---|
| committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-12-12 03:11:44 +0000 |
| commit | 5f58f9f701b9f5fd4d2372958e2b5392948840e6 (patch) | |
| tree | adcf94aab797d3820ad240cf8bb05827582c74a9 /string.c | |
| parent | a16e8ac05db7a236c897b9efd7502e3d6ea135a0 (diff) | |
| download | ruby-5f58f9f701b9f5fd4d2372958e2b5392948840e6.tar.gz ruby-5f58f9f701b9f5fd4d2372958e2b5392948840e6.tar.xz ruby-5f58f9f701b9f5fd4d2372958e2b5392948840e6.zip | |
* re.c (rb_reg_regsub): should copy encoding.
* string.c (rb_str_sub_bang, str_gsub): should check and copy encoding
to be replaced.
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@14197 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'string.c')
| -rw-r--r-- | string.c | 9 |
1 files changed, 9 insertions, 0 deletions
@@ -2370,15 +2370,19 @@ rb_str_sub_bang(int argc, VALUE *argv, VALUE str) if (iter) { char *p = RSTRING_PTR(str); long len = RSTRING_LEN(str); + rb_encoding *enc; rb_match_busy(match); repl = rb_obj_as_string(rb_yield(rb_reg_nth_match(0, match))); + enc = rb_enc_check(str, repl); str_mod_check(str, p, len); str_frozen_check(str); rb_backref_set(match); + rb_enc_associate(str, enc); } else { repl = rb_reg_regsub(repl, str, regs, pat); + rb_enc_copy(str, repl); } rb_str_modify(str); if (OBJ_TAINTED(repl)) tainted = 1; @@ -2490,17 +2494,22 @@ str_gsub(int argc, VALUE *argv, VALUE str, int bang) match = rb_backref_get(); regs = RMATCH(match)->regs; if (iter) { + rb_encoding *enc; + rb_match_busy(match); val = rb_obj_as_string(rb_yield(rb_reg_nth_match(0, match))); + enc = rb_enc_check(str, val); str_mod_check(str, sp, slen); if (bang) str_frozen_check(str); if (val == dest) { /* paranoid chack [ruby-dev:24827] */ rb_raise(rb_eRuntimeError, "block should not cheat"); } rb_backref_set(match); + rb_enc_associate(str, enc); } else { val = rb_reg_regsub(repl, str, regs, pat); + rb_enc_copy(str, val); } if (OBJ_TAINTED(val)) tainted = 1; len = (bp - buf) + (beg - offset) + RSTRING_LEN(val) + 3; |
