From 0a8f047a983deaf853e8ddc9f70da78f3a83f9ef Mon Sep 17 00:00:00 2001 From: naruse Date: Tue, 12 Oct 2010 06:18:11 +0000 Subject: [PATCH] * io.c (rb_io_putc): support multibyte characters. [ruby-core:30697] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29447 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 +++++ NEWS | 4 ++++ io.c | 12 +++++++++--- test/ruby/test_io_m17n.rb | 10 ++++++++++ 4 files changed, 28 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 790e4bc0cc..81ffc84791 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Tue Oct 12 15:14:21 2010 NARUSE, Yui + + * io.c (rb_io_putc): support multibyte characters. + [ruby-core:30697] + Tue Oct 12 15:10:31 2010 NARUSE, Yui * numeric.c (rb_enc_uint_chr): split from int_chr. diff --git a/NEWS b/NEWS index d6c7e39dfa..2d6e6df552 100644 --- a/NEWS +++ b/NEWS @@ -40,6 +40,10 @@ with all sufficient information, see the ChangeLog file. * extended methods: * Time#strftime supports %:z and %::z. + * IO + * extended methods: + * IO#putc supports multibyte characters + * io/console * new methods: * IO#noecho {|io| } diff --git a/io.c b/io.c index 7255fc46f4..7625796b2b 100644 --- a/io.c +++ b/io.c @@ -6053,9 +6053,15 @@ rb_f_print(int argc, VALUE *argv) static VALUE rb_io_putc(VALUE io, VALUE ch) { - char c = NUM2CHR(ch); - - rb_io_write(io, rb_str_new(&c, 1)); + VALUE str; + if (TYPE(ch) == T_STRING) { + str = rb_str_substr(ch, 0, 1); + } + else { + char c = NUM2CHR(ch); + str = rb_str_new(&c, 1); + } + rb_io_write(io, str); return ch; } diff --git a/test/ruby/test_io_m17n.rb b/test/ruby/test_io_m17n.rb index 3d3b64c6cc..5f35c227ea 100644 --- a/test/ruby/test_io_m17n.rb +++ b/test/ruby/test_io_m17n.rb @@ -1026,6 +1026,16 @@ EOT } end + def test_open_pipe_r_enc2 + open("|#{EnvUtil.rubybin} -e 'putc ?\u3042'", "r:UTF-8") {|f| + assert_equal(Encoding::UTF_8, f.external_encoding) + assert_equal(nil, f.internal_encoding) + s = f.read + assert_equal(Encoding::UTF_8, s.encoding) + assert_equal("\u3042", s) + } + end + def test_s_foreach_enc with_tmpdir { generate_file("t", "\xff")