summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2018-02-12 10:29:24 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2018-02-12 22:56:24 +0900
commit1d5526042394630a1c69b0d2169fa02cce36c20a (patch)
tree93a6f86207870a2ba0ed2e29b3f078919486cf05
parentb9523d0e06149dd0747250dcc344bdc2feb3ef4b (diff)
downloadmruby-1d5526042394630a1c69b0d2169fa02cce36c20a.tar.gz
mruby-1d5526042394630a1c69b0d2169fa02cce36c20a.zip
`String#inspect` to use hexadecimal, not octal to print unprintable.
-rw-r--r--src/string.c14
-rw-r--r--test/t/string.rb2
2 files changed, 8 insertions, 8 deletions
diff --git a/src/string.c b/src/string.c
index c2284d552..e8c60a660 100644
--- a/src/string.c
+++ b/src/string.c
@@ -2542,10 +2542,10 @@ mrb_str_dump(mrb_state *mrb, mrb_value str)
}
else {
*q++ = '\\';
- q[2] = '0' + c % 8; c /= 8;
- q[1] = '0' + c % 8; c /= 8;
- q[0] = '0' + c % 8;
- q += 3;
+ *q++ = 'x';
+ q[1] = mrb_digitmap[c % 16]; c /= 16;
+ q[0] = mrb_digitmap[c % 16];
+ q += 2;
}
}
}
@@ -2685,9 +2685,9 @@ mrb_str_inspect(mrb_state *mrb, mrb_value str)
}
else {
buf[0] = '\\';
- buf[3] = '0' + c % 8; c /= 8;
- buf[2] = '0' + c % 8; c /= 8;
- buf[1] = '0' + c % 8;
+ buf[1] = 'x';
+ buf[3] = mrb_digitmap[c % 16]; c /= 16;
+ buf[2] = mrb_digitmap[c % 16];
mrb_str_cat(mrb, result, buf, 4);
continue;
}
diff --git a/test/t/string.rb b/test/t/string.rb
index 6351d5d98..a1277ce99 100644
--- a/test/t/string.rb
+++ b/test/t/string.rb
@@ -685,7 +685,7 @@ assert('String#inspect', '15.2.10.5.46') do
("\1" * 100).inspect
end
- assert_equal "\"\\000\"", "\0".inspect
+ assert_equal "\"\\x00\"", "\0".inspect
end
# Not ISO specified