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

ruby-changes:17896

From: yugui <ko1@a...>
Date: Wed, 24 Nov 2010 18:37:22 +0900 (JST)
Subject: [ruby-changes:17896] Ruby:r29909 (ruby_1_9_2): merges r29256 from trunk into ruby_1_9_2.

yugui	2010-11-24 18:37:02 +0900 (Wed, 24 Nov 2010)

  New Revision: 29909

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

  Log:
    merges r29256 from trunk into ruby_1_9_2.
    --
    * io.c (rb_io_puts): fix for wide char encoding strings.
      [ruby-dev:42212]

  Modified files:
    branches/ruby_1_9_2/ChangeLog
    branches/ruby_1_9_2/io.c
    branches/ruby_1_9_2/test/ruby/test_io_m17n.rb
    branches/ruby_1_9_2/version.h

Index: ruby_1_9_2/ChangeLog
===================================================================
--- ruby_1_9_2/ChangeLog	(revision 29908)
+++ ruby_1_9_2/ChangeLog	(revision 29909)
@@ -1,3 +1,8 @@
+Wed Sep 15 09:12:03 2010  Nobuyoshi Nakada  <nobu@r...>
+
+	* io.c (rb_io_puts): fix for wide char encoding strings.
+	  [ruby-dev:42212]
+
 Wed Sep 15 07:27:52 2010  Nobuyoshi Nakada  <nobu@r...>
 
 	* string.c (rb_str_times): mentioned about Hash argument.  a patch
Index: ruby_1_9_2/io.c
===================================================================
--- ruby_1_9_2/io.c	(revision 29908)
+++ ruby_1_9_2/io.c	(revision 29909)
@@ -6061,6 +6061,22 @@
     return rb_funcall2(rb_stdout, rb_intern("putc"), 1, &ch);
 }
 
+
+static int
+str_end_with_asciichar(VALUE str, int c)
+{
+    long len = RSTRING_LEN(str);
+    const char *ptr = RSTRING_PTR(str);
+    rb_encoding *enc = rb_enc_from_index(ENCODING_GET(str));
+    int n;
+
+    if (len == 0) return 0;
+    if ((n = rb_enc_mbminlen(enc)) == 1) {
+	return ptr[len - 1] == c;
+    }
+    return rb_enc_ascget(ptr + ((len - 1) / n) * n, ptr + len, &n, enc) == c;
+}
+
 static VALUE
 io_puts_ary(VALUE ary, VALUE out, int recur)
 {
@@ -6124,7 +6140,7 @@
       string:
 	rb_io_write(out, line);
 	if (RSTRING_LEN(line) == 0 ||
-            RSTRING_PTR(line)[RSTRING_LEN(line)-1] != '\n') {
+            !str_end_with_asciichar(line, '\n')) {
 	    rb_io_write(out, rb_default_rs);
 	}
     }
Index: ruby_1_9_2/version.h
===================================================================
--- ruby_1_9_2/version.h	(revision 29908)
+++ ruby_1_9_2/version.h	(revision 29909)
@@ -1,13 +1,13 @@
 #define RUBY_VERSION "1.9.2"
-#define RUBY_PATCHLEVEL 42
+#define RUBY_PATCHLEVEL 43
 #define RUBY_VERSION_MAJOR 1
 #define RUBY_VERSION_MINOR 9
 #define RUBY_VERSION_TEENY 1
 
 #define RUBY_RELEASE_YEAR 2010
 #define RUBY_RELEASE_MONTH 11
-#define RUBY_RELEASE_DAY 15
-#define RUBY_RELEASE_DATE "2010-11-15"
+#define RUBY_RELEASE_DAY 24
+#define RUBY_RELEASE_DATE "2010-11-24"
 
 #include "ruby/version.h"
 
Index: ruby_1_9_2/test/ruby/test_io_m17n.rb
===================================================================
--- ruby_1_9_2/test/ruby/test_io_m17n.rb	(revision 29908)
+++ ruby_1_9_2/test/ruby/test_io_m17n.rb	(revision 29909)
@@ -1833,5 +1833,23 @@
       assert_equal((bug3534[1]+"\n").encode(e), r.gets(), bug3534[1])
     end
   end
+
+  def test_puts_widechar
+    bug = '[ruby-dev:42212]'
+    r, w = IO.pipe(Encoding::ASCII_8BIT)
+    r.binmode
+    w.binmode
+    w.puts(0x010a.chr(Encoding::UTF_32BE))
+    w.puts(0x010a.chr(Encoding::UTF_16BE))
+    w.puts(0x0a010000.chr(Encoding::UTF_32LE))
+    w.puts(0x0a01.chr(Encoding::UTF_16LE))
+    w.close
+    assert_equal("\x00\x00\x01\x0a\n", r.read(5), bug)
+    assert_equal("\x01\x0a\n", r.read(3), bug)
+    assert_equal("\x00\x00\x01\x0a\n", r.read(5), bug)
+    assert_equal("\x01\x0a\n", r.read(3), bug)
+    assert_equal("", r.read, bug)
+    r.close
+  end
 end
 

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

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