mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* string.c (sym_inspect): quote if symbol contains non-printable
characters. [ruby-dev:37398] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@20723 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
d6023d88a2
commit
0241c6506f
2 changed files with 18 additions and 1 deletions
|
@ -14,6 +14,9 @@ Sat Dec 13 15:52:27 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||||
* string.c (sym_equal): remove documentation error "Otherwise,
|
* string.c (sym_equal): remove documentation error "Otherwise,
|
||||||
compares them as strings". [ruby-dev:37398]
|
compares them as strings". [ruby-dev:37398]
|
||||||
|
|
||||||
|
* string.c (sym_inspect): quote if symbol contains non-printable
|
||||||
|
characters. [ruby-dev:37398]
|
||||||
|
|
||||||
Sat Dec 13 14:24:38 2008 Yuki Sonoda (Yugui) <yugui@yugui.jp>
|
Sat Dec 13 14:24:38 2008 Yuki Sonoda (Yugui) <yugui@yugui.jp>
|
||||||
|
|
||||||
* test/ruby/enc/test_utf16.rb: feature changed in r20626.
|
* test/ruby/enc/test_utf16.rb: feature changed in r20626.
|
||||||
|
|
16
string.c
16
string.c
|
@ -6826,6 +6826,19 @@ sym_equal(VALUE sym1, VALUE sym2)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int
|
||||||
|
sym_printable(const char *s, rb_encoding *enc)
|
||||||
|
{
|
||||||
|
const char *send = s + strlen(s);
|
||||||
|
while (s) {
|
||||||
|
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:
|
* call-seq:
|
||||||
* sym.inspect => string
|
* sym.inspect => string
|
||||||
|
@ -6848,7 +6861,8 @@ sym_inspect(VALUE sym)
|
||||||
RSTRING_PTR(str)[0] = ':';
|
RSTRING_PTR(str)[0] = ':';
|
||||||
memcpy(RSTRING_PTR(str)+1, RSTRING_PTR(sym), RSTRING_LEN(sym));
|
memcpy(RSTRING_PTR(str)+1, RSTRING_PTR(sym), RSTRING_LEN(sym));
|
||||||
if (RSTRING_LEN(sym) != strlen(RSTRING_PTR(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), enc)) {
|
||||||
str = rb_str_inspect(str);
|
str = rb_str_inspect(str);
|
||||||
strncpy(RSTRING_PTR(str), ":\"", 2);
|
strncpy(RSTRING_PTR(str), ":\"", 2);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue