From 20711ffa57b2d59841785d296d0b346d7a5eaaba Mon Sep 17 00:00:00 2001 From: kichikuou Date: Tue, 12 Aug 2025 08:39:32 +0900 Subject: [PATCH] S_MOD: Consider padding for FMT_STRING --- src/format.c | 12 ++++++++++-- test/Source/strings.jaf | 1 + 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/format.c b/src/format.c index b167073..6e698d9 100644 --- a/src/format.c +++ b/src/format.c @@ -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; diff --git a/test/Source/strings.jaf b/test/Source/strings.jaf index ca9afc8..6abd044 100755 --- a/test/Source/strings.jaf +++ b/test/Source/strings.jaf @@ -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