From 3f3e44962cedb1e5c607f62004789d6876ab0ff0 Mon Sep 17 00:00:00 2001 From: naruse Date: Tue, 29 Sep 2009 15:02:59 +0000 Subject: Escape as \x{XXXX} other than Unicode chars. * string.c (rb_str_inspect): escape as \x{XXXX} when the encoding is other than Unicode. [ruby-dev:39388] git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@25163 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- string.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) (limited to 'string.c') diff --git a/string.c b/string.c index 4ee979ee8..3ba6693a1 100644 --- a/string.c +++ b/string.c @@ -4123,21 +4123,30 @@ rb_str_inspect(VALUE str) char buf[11]; escape_codepoint: - if (unicode_p && c != -1) { - if (c > 0xFFFF) { - sprintf(buf, "\\u{%X}", c); + if (c == -1) { + char *q; + for (q = p-n; q < p; q++) { + sprintf(buf, "\\x%02X", *q & 0377); + str_buf_cat(result, buf, strlen(buf)); } - else { + } + else if (unicode_p) { + if (c < 0x10000) { sprintf(buf, "\\u%04X", c); } + else { + sprintf(buf, "\\u{%X}", c); + } str_buf_cat(result, buf, strlen(buf)); } else { - char *q; - for (q = p-n; q < p; q++) { - sprintf(buf, "\\x%02X", *q & 0377); - str_buf_cat(result, buf, strlen(buf)); + if (c < 0x100) { + sprintf(buf, "\\x%02X", c); + } + else { + sprintf(buf, "\\x{%X}", c); } + str_buf_cat(result, buf, strlen(buf)); } } } -- cgit