1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/ext/-test-/printf/printf.c
nobu 09adba0dc1 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
2013-07-30 08:16:20 +00:00

38 lines
930 B
C

#include <ruby.h>
#include <ruby/encoding.h>
static VALUE
printf_test_i(VALUE self, VALUE obj)
{
char buf[256];
snprintf(buf, sizeof(buf), "<%"PRIsVALUE">", obj);
return rb_usascii_str_new2(buf);
}
static VALUE
printf_test_s(VALUE self, VALUE obj)
{
return rb_enc_sprintf(rb_usascii_encoding(), "<%"PRIsVALUE">", obj);
}
static VALUE
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)
{
VALUE m = rb_define_module_under(rb_define_module("Bug"), "Printf");
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);
}