mirror of
https://github.com/nunuhara/xsystem4.git
synced 2026-09-30 10:58:15 +03:00
Merge pull request #264 from kichikuou/s_mod
S_MOD: Consider padding for FMT_STRING
This commit is contained in:
+10
-2
@@ -145,10 +145,18 @@ static void append_fmt(struct string **s, struct fmt_spec *spec, union vm_value
|
||||
len = float_to_cstr(buf, DIGIT_MAX, arg.f, spec->padding, spec->zero_pad, spec->precision, spec->zenkaku);
|
||||
string_append_cstr(s, buf, len);
|
||||
break;
|
||||
case FMT_STRING:
|
||||
string_append(s, heap_get_string(arg.i));
|
||||
case FMT_STRING: {
|
||||
struct string *val = heap_get_string(arg.i);
|
||||
int pad_len = spec->padding - val->size;
|
||||
if (pad_len > 0) {
|
||||
for (int i = 0; i < pad_len; i++) {
|
||||
string_push_back(s, ' ');
|
||||
}
|
||||
}
|
||||
string_append(s, val);
|
||||
heap_unref(arg.i);
|
||||
break;
|
||||
}
|
||||
case FMT_CHAR:
|
||||
string_push_back(s, arg.i);
|
||||
break;
|
||||
|
||||
@@ -84,6 +84,7 @@ void test_strings(void)
|
||||
test_string("abc%8.2Fdef % 12.3", "abc%8.2Fdef" % 12.3, "abc 12.30Fdef");
|
||||
// string
|
||||
test_string("abc%sdef % \"あいう\"", "abc%sdef" % "あいう", "abcあいうdef");
|
||||
test_string("(%8s) % \"あb\"", "(%8s)" % "あb", "( あb)");
|
||||
// char
|
||||
test_string("abc%cdef % 'あ'", "abc%cdef" % 'あ', "abcあdef");
|
||||
// bool
|
||||
|
||||
Reference in New Issue
Block a user