1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* 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/trunk@28104 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
naruse 2010-05-31 06:04:27 +00:00
parent d13e191d25
commit d16fc7ca69
3 changed files with 15 additions and 1 deletions

View file

@ -1,3 +1,8 @@
Mon May 31 14:47:09 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.
Mon May 31 13:44:40 2010 NARUSE, Yui <naruse@ruby-lang.org>
* encoding.c (rb_enc_unicode_p): check the encoding is Unicode

View file

@ -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 {

View file

@ -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