[前][次][番号順一覧][スレッド一覧]

ruby-changes:17442

From: naruse <ko1@a...>
Date: Tue, 12 Oct 2010 15:18:20 +0900 (JST)
Subject: [ruby-changes:17442] Ruby:r29447 (trunk): * io.c (rb_io_putc): support multibyte characters.

naruse	2010-10-12 15:18:11 +0900 (Tue, 12 Oct 2010)

  New Revision: 29447

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=29447

  Log:
    * io.c (rb_io_putc): support multibyte characters.
      [ruby-core:30697]

  Modified files:
    trunk/ChangeLog
    trunk/NEWS
    trunk/io.c
    trunk/test/ruby/test_io_m17n.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 29446)
+++ ChangeLog	(revision 29447)
@@ -1,3 +1,8 @@
+Tue Oct 12 15:14:21 2010  NARUSE, Yui  <naruse@r...>
+
+	* io.c (rb_io_putc): support multibyte characters.
+	  [ruby-core:30697]
+
 Tue Oct 12 15:10:31 2010  NARUSE, Yui  <naruse@r...>
 
 	* numeric.c (rb_enc_uint_chr): split from int_chr.
Index: io.c
===================================================================
--- io.c	(revision 29446)
+++ io.c	(revision 29447)
@@ -6053,9 +6053,15 @@
 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;
 }
 
Index: NEWS
===================================================================
--- NEWS	(revision 29446)
+++ NEWS	(revision 29447)
@@ -40,6 +40,10 @@
     * extended methods:
       * Time#strftime supports %:z and %::z.
 
+  * IO
+    * extended methods:
+      * IO#putc supports multibyte characters
+
 * io/console
   * new methods:
     * IO#noecho {|io| }
Index: test/ruby/test_io_m17n.rb
===================================================================
--- test/ruby/test_io_m17n.rb	(revision 29446)
+++ test/ruby/test_io_m17n.rb	(revision 29447)
@@ -1026,6 +1026,16 @@
     }
   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")

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]