1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

sprintf.c: QUOTE flag

* sprintf.c (ruby__sfvextra): add QUOTE flag to escape unprintable
  characters.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42251 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2013-07-30 08:16:20 +00:00
parent 6be21c1de0
commit 09adba0dc1
4 changed files with 24 additions and 0 deletions

View file

@ -1,3 +1,13 @@
Tue Jul 30 17:16:15 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
* sprintf.c (ruby__sfvextra): add QUOTE flag to escape unprintable
characters.
Tue Jul 30 17:09:51 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
* sprintf.c (ruby__sfvextra): add QUOTE flag to escape unprintable
characters.
Tue Jul 30 11:00:52 2013 Zachary Scott <e@zzak.io>
* ext/curses/extconf.rb: [DOC] nodoc to reduce Object pollution

View file

@ -21,6 +21,12 @@ printf_test_v(VALUE self, VALUE obj)
return rb_enc_sprintf(rb_usascii_encoding(), "{%+"PRIsVALUE"}", obj);
}
static VALUE
printf_test_q(VALUE self, VALUE obj)
{
return rb_enc_sprintf(rb_usascii_encoding(), "[% "PRIsVALUE"]", obj);
}
void
Init_printf(void)
{
@ -28,4 +34,5 @@ Init_printf(void)
rb_define_singleton_method(m, "i", printf_test_i, 1);
rb_define_singleton_method(m, "s", printf_test_s, 1);
rb_define_singleton_method(m, "v", printf_test_v, 1);
rb_define_singleton_method(m, "q", printf_test_q, 1);
}

View file

@ -1171,6 +1171,7 @@ ruby__sfvextra(rb_printf_buffer *fp, size_t valsize, void *valp, long *sz, int s
}
else {
value = rb_obj_as_string(value);
if (sign == ' ') value = QUOTE(value);
}
enc = rb_enc_compatible(result, value);
if (enc) {

View file

@ -22,6 +22,12 @@ class Test_SPrintf < Test::Unit::TestCase
assert_equal("{<#{self.class}:#{object_id}>}", Bug::Printf.v(self))
end
def test_quote
assert_equal('["\n"]', Bug::Printf.q("\n"))
assert_equal('[aaa]', Bug::Printf.q('aaa'))
assert_equal('[a a]', Bug::Printf.q('a a'))
end
def test_encoding
def self.to_s
"\u{3042 3044 3046 3048 304a}"