ruby-changes:50598
From: nobu <ko1@a...>
Date: Wed, 14 Mar 2018 11:35:58 +0900 (JST)
Subject: [ruby-changes:50598] nobu:r62747 (trunk): quote symbols
nobu 2018-03-14 11:35:51 +0900 (Wed, 14 Mar 2018) New Revision: 62747 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=62747 Log: quote symbols * sprintf.c (ruby__sfvextra): quote symbols as identifiers. * string.c (rb_id_quote_unprintable): ditto. Modified files: trunk/sprintf.c trunk/string.c trunk/test/-ext-/test_printf.rb Index: string.c =================================================================== --- string.c (revision 62746) +++ string.c (revision 62747) @@ -10364,7 +10364,7 @@ rb_str_symname_p(VALUE sym) https://github.com/ruby/ruby/blob/trunk/string.c#L10364 ptr = RSTRING_PTR(sym); len = RSTRING_LEN(sym); if ((resenc != enc && !rb_str_is_ascii_only_p(sym)) || len != (long)strlen(ptr) || - !rb_enc_symname_p(ptr, enc) || !sym_printable(ptr, ptr + len, enc)) { + !rb_enc_symname2_p(ptr, len, enc) || !sym_printable(ptr, ptr + len, enc)) { return FALSE; } return TRUE; @@ -10394,7 +10394,11 @@ rb_str_quote_unprintable(VALUE str) https://github.com/ruby/ruby/blob/trunk/string.c#L10394 MJIT_FUNC_EXPORTED VALUE rb_id_quote_unprintable(ID id) { - return rb_str_quote_unprintable(rb_id2str(id)); + VALUE str = rb_id2str(id); + if (!rb_str_symname_p(str)) { + return rb_str_inspect(str); + } + return str; } /* Index: test/-ext-/test_printf.rb =================================================================== --- test/-ext-/test_printf.rb (revision 62746) +++ test/-ext-/test_printf.rb (revision 62747) @@ -24,6 +24,8 @@ class Test_SPrintf < Test::Unit::TestCas https://github.com/ruby/ruby/blob/trunk/test/-ext-/test_printf.rb#L24 assert_equal('["\n"]', Bug::Printf.q("\n")) assert_equal('[aaa]', Bug::Printf.q('aaa')) assert_equal('[a a]', Bug::Printf.q('a a')) + assert_equal('[]', Bug::Printf.q('')) + assert_equal('[""]', Bug::Printf.q(:'')) end def test_encoding Index: sprintf.c =================================================================== --- sprintf.c (revision 62746) +++ sprintf.c (revision 62747) @@ -1378,6 +1378,12 @@ ruby__sfvextra(rb_printf_buffer *fp, siz https://github.com/ruby/ruby/blob/trunk/sprintf.c#L1378 } value = rb_inspect(value); } + else if (SYMBOL_P(value)) { + value = rb_sym2str(value); + if (sign == ' ' && !rb_str_symname_p(value)) { + value = rb_str_inspect(value); + } + } else { value = rb_obj_as_string(value); if (sign == ' ') value = QUOTE(value); -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/