mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
string.c: term fill
* string.c (tr_trans): fill wchar terminator. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48777 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
1d60b6eff9
commit
88ae402cbf
2 changed files with 16 additions and 2 deletions
4
string.c
4
string.c
|
@ -5671,7 +5671,7 @@ tr_trans(VALUE str, VALUE src, VALUE repl, int sflag)
|
|||
if (!STR_EMBED_P(str)) {
|
||||
ruby_sized_xfree(STR_HEAP_PTR(str), STR_HEAP_SIZE(str));
|
||||
}
|
||||
*t = '\0';
|
||||
TERM_FILL(t, rb_enc_mbminlen(enc));
|
||||
RSTRING(str)->as.heap.ptr = buf;
|
||||
RSTRING(str)->as.heap.len = t - buf;
|
||||
STR_SET_NOEMBED(str);
|
||||
|
@ -5747,7 +5747,7 @@ tr_trans(VALUE str, VALUE src, VALUE repl, int sflag)
|
|||
if (!STR_EMBED_P(str)) {
|
||||
ruby_sized_xfree(STR_HEAP_PTR(str), STR_HEAP_SIZE(str));
|
||||
}
|
||||
*t = '\0';
|
||||
TERM_FILL(t, rb_enc_mbminlen(enc));
|
||||
RSTRING(str)->as.heap.ptr = buf;
|
||||
RSTRING(str)->as.heap.len = t - buf;
|
||||
STR_SET_NOEMBED(str);
|
||||
|
|
|
@ -72,6 +72,20 @@ class Test_StringCStr < Test::Unit::TestCase
|
|||
assert_wchars_term_char("foo!") {|s| s.squeeze!}
|
||||
end
|
||||
|
||||
def test_wchar_tr!
|
||||
assert_wchars_term_char("\u{3042}foobar") {|s|
|
||||
enc = s.encoding
|
||||
s.tr!("\u{3042}".encode(enc), "c".encode(enc))
|
||||
}
|
||||
end
|
||||
|
||||
def test_wchar_tr_s!
|
||||
assert_wchars_term_char("\u{3042}foobar") {|s|
|
||||
enc = s.encoding
|
||||
s.tr_s!("\u{3042}".encode(enc), "c".encode(enc))
|
||||
}
|
||||
end
|
||||
|
||||
def assert_wchars_term_char(str)
|
||||
result = {}
|
||||
WCHARS.map do |enc|
|
||||
|
|
Loading…
Add table
Reference in a new issue