Feature #16779 ยป add-quoted-string-sprintf-format.patch
| sprintf.c | ||
|---|---|---|
|
}
|
||
|
}
|
||
|
break;
|
||
|
case 's':
|
||
|
case 'p':
|
||
|
case 'q':
|
||
|
case 's':
|
||
|
case 'p':
|
||
|
format_s:
|
||
|
{
|
||
|
VALUE arg = GETARG();
|
||
| ... | ... | |
|
if (*p == 'p') {
|
||
|
str = rb_inspect(arg);
|
||
|
}
|
||
|
else if (*p == 'q') {
|
||
|
str = rb_obj_as_string(arg);
|
||
|
str = rb_str_dump(str);
|
||
|
}
|
||
|
else {
|
||
|
str = rb_obj_as_string(arg);
|
||
|
}
|
||
|
len = RSTRING_LEN(str);
|
||
|
rb_str_set_len(result, blen);
|
||
|
if (coderange != ENC_CODERANGE_BROKEN && scanned < blen) {
|
||
| test/ruby/test_sprintf.rb | ||
|---|---|---|
|
assert_equal("foo" + " " * BSIZ, sprintf("%-#{ BSIZ + 3 }s", "foo"))
|
||
|
end
|
||
|
def test_quoted_string
|
||
|
assert_equal(%q{"foo"}, sprintf("%q", "foo"))
|
||
|
assert_equal(%q{"foo\n bar"}, sprintf("%q", "foo\n bar"))
|
||
|
assert_equal(%q{"foo\r bar"}, sprintf("%q", "foo\r bar"))
|
||
|
end
|
||
|
def test_integer
|
||
|
assert_equal("01", sprintf("%#o", 1))
|
||
|
assert_equal("0x1", sprintf("%#x", 1))
|
||