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

ruby-changes:16144

From: naruse <ko1@a...>
Date: Mon, 31 May 2010 15:04:48 +0900 (JST)
Subject: [ruby-changes:16144] Ruby:r28104 (trunk): * string.c (rb_str_inspect): inspect as ASCII when the codepoint

naruse	2010-05-31 15:04:27 +0900 (Mon, 31 May 2010)

  New Revision: 28104

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

  Log:
    * string.c (rb_str_inspect): inspect as ASCII when the codepoint
      of a character in Unicode string is ASCII printable one.

  Modified files:
    trunk/ChangeLog
    trunk/string.c
    trunk/test/ruby/test_m17n.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 28103)
+++ ChangeLog	(revision 28104)
@@ -1,3 +1,8 @@
+Mon May 31 14:47:09 2010  NARUSE, Yui  <naruse@r...>
+
+	* string.c (rb_str_inspect): inspect as ASCII when the codepoint
+	  of a character in Unicode string is ASCII printable one.
+
 Mon May 31 13:44:40 2010  NARUSE, Yui  <naruse@r...>
 
 	* encoding.c (rb_enc_unicode_p): check the encoding is Unicode
Index: string.c
===================================================================
--- string.c	(revision 28103)
+++ string.c	(revision 28104)
@@ -4166,7 +4166,10 @@
 	else {
 	    if (p - n > prev) str_buf_cat(result, prev, p - n - prev);
 	    if (unicode_p) {
-		if (c < 0x10000) {
+		if (c < 0x100 && ISPRINT(c)) {
+		    snprintf(buf, CHAR_ESC_LEN, "%c", c);
+		}
+		else if (c < 0x10000) {
 		    snprintf(buf, CHAR_ESC_LEN, "\\u%04X", c);
 		}
 		else {
Index: test/ruby/test_m17n.rb
===================================================================
--- test/ruby/test_m17n.rb	(revision 28103)
+++ test/ruby/test_m17n.rb	(revision 28104)
@@ -221,6 +221,12 @@
       str = "\u3042\u{10FFFD}"
       assert_equal(Encoding::UTF_8 == e ? %{"#{str}"} : '"\u3042\u{10FFFD}"', str.inspect)
     end
+    Encoding.default_external = Encoding::UTF_8
+    [Encoding::UTF_16BE, Encoding::UTF_16LE, Encoding::UTF_32BE, Encoding::UTF_32LE,
+      Encoding::UTF8_SOFTBANK].each do |e|
+      str = "abc".encode(e)
+      assert_equal('"abc"', str.inspect)
+    end
   ensure
     Encoding.default_internal = orig_int
     Encoding.default_external = orig_ext

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

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