Merge pull request #264 from kichikuou/s_mod

S_MOD: Consider padding for FMT_STRING
This commit is contained in:
Nunuhara Cabbage
2025-08-15 13:51:56 -07:00
committed by GitHub
2 changed files with 11 additions and 2 deletions
+10 -2
View File
@@ -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;
+1
View File
@@ -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