diff options
author | yugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-12-16 10:25:58 +0000 |
---|---|---|
committer | yugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-12-16 10:25:58 +0000 |
commit | d1167ba077883491593e6f7e5ddb7b0f12cb1143 (patch) | |
tree | 8140238f8b9e2ce06c58675f0d63a3c3c96b0bab /string.c | |
parent | 2eb71691f9b7c7b5c81fe410cf8d87c552ba9e21 (diff) |
merges r20723 and r20724 from trunk into ruby_1_9_1.
* string.c (sym_inspect): quote if symbol contains non-printable
characters. [ruby-dev:37398]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_1@20790 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'string.c')
-rw-r--r-- | string.c | 15 |
1 files changed, 14 insertions, 1 deletions
@@ -6826,6 +6826,18 @@ sym_equal(VALUE sym1, VALUE sym2) } +static int +sym_printable(const char *s, const char *send, rb_encoding *enc) +{ + while (s < send) { + int c = rb_enc_codepoint(s, send, enc); + int n = rb_enc_codelen(c, enc); + if (!rb_enc_isprint(c, enc)) return Qfalse; + s += n; + } + return Qtrue; +} + /* * call-seq: * sym.inspect => string @@ -6848,7 +6860,8 @@ sym_inspect(VALUE sym) RSTRING_PTR(str)[0] = ':'; memcpy(RSTRING_PTR(str)+1, RSTRING_PTR(sym), RSTRING_LEN(sym)); if (RSTRING_LEN(sym) != strlen(RSTRING_PTR(sym)) || - !rb_enc_symname_p(RSTRING_PTR(sym), enc)) { + !rb_enc_symname_p(RSTRING_PTR(sym), enc) || + !sym_printable(RSTRING_PTR(sym), RSTRING_END(sym), enc)) { str = rb_str_inspect(str); strncpy(RSTRING_PTR(str), ":\"", 2); } |