diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2000-12-28 04:45:16 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2000-12-28 04:45:16 +0000 |
commit | fd850de8a8d39493d279372b262883f0e94f568e (patch) | |
tree | 19cb84185abeb70fde3185015e94ac340d734a16 /string.c | |
parent | bb499cc2cb477bb4dfeff728e5c2de4f84e97acb (diff) |
matz
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_6@1083 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'string.c')
-rw-r--r-- | string.c | 12 |
1 files changed, 8 insertions, 4 deletions
@@ -1316,15 +1316,19 @@ static VALUE rb_str_replace_m(str, str2) VALUE str, str2; { + if (str == str2) return str; if (TYPE(str2) != T_STRING) str2 = rb_str_to_str(str2); - rb_str_modify(str); - if (RSTRING(str2)->orig && FL_TEST(str2, STR_NO_ORIG)) { + if (RSTRING(str2)->orig && !FL_TEST(str2, STR_NO_ORIG)) { + if (str_independent(str)) + free(RSTRING(str)->ptr); + RSTRING(str)->len = RSTRING(str2)->len; RSTRING(str)->ptr = RSTRING(str2)->ptr; RSTRING(str)->orig = RSTRING(str2)->orig; } else { + rb_str_modify(str); rb_str_resize(str, RSTRING(str2)->len); memcpy(RSTRING(str)->ptr, RSTRING(str2)->ptr, RSTRING(str2)->len); } @@ -1490,8 +1494,8 @@ rb_str_inspect(str) char c = *p++; if (ismbchar(c) && p < pend) { int len = mbclen(c); - rb_str_cat(result, p, len); - p += len; + rb_str_cat(result, p - 1, len); + p += len - 1; } else if (c == '"'|| c == '\\') { s[0] = '\\'; s[1] = c; |