1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
#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);
}
|