summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-06-05 14:15:15 +0000
committernaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-06-05 14:15:15 +0000
commite1c14eabd548d275e3f978192260c8a7d619cc71 (patch)
tree18ee180061bab005ddf11c639def16a0815254fa
parentf229a0642e7dd09c5b88b8041be4e6df0829371a (diff)
merge revision(s) 28104:
* string.c (rb_str_inspect): inspect as ASCII when the codepoint of a character in Unicode string is ASCII printable one. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_2@28179 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog5
-rw-r--r--string.c5
-rw-r--r--test/ruby/test_m17n.rb6
3 files changed, 15 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 89df009f4f..f760f9a7f3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Sat Jun 5 23:14:51 2010 NARUSE, Yui <naruse@ruby-lang.org>
+
+ * string.c (rb_str_inspect): inspect as ASCII when the codepoint
+ of a character in Unicode string is ASCII printable one.
+
Sat Jun 5 15:59:08 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>
* ruby.c (process_options, load_file_internal): $0 seen from
diff --git a/string.c b/string.c
index ae4289380f..48ebf89815 100644
--- a/string.c
+++ b/string.c
@@ -4166,7 +4166,10 @@ rb_str_inspect(VALUE str)
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 {
diff --git a/test/ruby/test_m17n.rb b/test/ruby/test_m17n.rb
index 6df58453d9..07cda751d1 100644
--- a/test/ruby/test_m17n.rb
+++ b/test/ruby/test_m17n.rb
@@ -221,6 +221,12 @@ class TestM17N < Test::Unit::TestCase
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