summaryrefslogtreecommitdiff
path: root/string.c
diff options
context:
space:
mode:
authornaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-09-29 15:02:59 +0000
committernaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-09-29 15:02:59 +0000
commit5b2d54be66528c659d8a29256d51f17e9955bc56 (patch)
tree1dc4620e4dcf3fb6ce75e63a3ab1ae7f99c245e7 /string.c
parente8f007e6b84d4db4c547da1d4b96d163380a78f6 (diff)
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: svn+ssh://ci.ruby-lang.org/ruby/trunk@25163 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'string.c')
-rw-r--r--string.c25
1 files changed, 17 insertions, 8 deletions
diff --git a/string.c b/string.c
index 4ee979ee81..3ba6693a17 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));
}
}
}