ruby-changes:36696
From: nobu <ko1@a...>
Date: Fri, 12 Dec 2014 10:20:47 +0900 (JST)
Subject: [ruby-changes:36696] nobu:r48777 (trunk): string.c: term fill
nobu 2014-12-12 10:20:41 +0900 (Fri, 12 Dec 2014) New Revision: 48777 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=48777 Log: string.c: term fill * string.c (tr_trans): fill wchar terminator. Modified files: trunk/string.c trunk/test/-ext-/string/test_cstr.rb Index: string.c =================================================================== --- string.c (revision 48776) +++ string.c (revision 48777) @@ -5671,7 +5671,7 @@ tr_trans(VALUE str, VALUE src, VALUE rep https://github.com/ruby/ruby/blob/trunk/string.c#L5671 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 rep https://github.com/ruby/ruby/blob/trunk/string.c#L5747 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); Index: test/-ext-/string/test_cstr.rb =================================================================== --- test/-ext-/string/test_cstr.rb (revision 48776) +++ test/-ext-/string/test_cstr.rb (revision 48777) @@ -72,6 +72,20 @@ class Test_StringCStr < Test::Unit::Test https://github.com/ruby/ruby/blob/trunk/test/-ext-/string/test_cstr.rb#L72 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| -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/