Berry format support width for %c format (#25122)

This commit is contained in:
s-hadinger authored and GitHub committed 2026-10-09 18:48:23 +02:00
1 parent 84b011242c
commit e2a665dfca
3 files changed
+8 -2

No files matched your search

+4 -1
View File
@@ -1373,7 +1373,10 @@ def be_str_format(vm):
elif spec == 'c':
ok, val = _convert_to_int(vm, index)
if ok:
buf = chr(int(val) & 0xFF)
try:
buf = mode % chr(int(val) & 0xFF)
except (TypeError, ValueError):
buf = chr(int(val) & 0xFF)
be_api.be_pushstring(vm, buf)
elif spec == 's':
s = be_api.be_tostring(vm, index)
+1 -1
View File
@@ -832,7 +832,7 @@ int be_str_format(bvm *vm)
{
bint val;
if (convert_to_int(vm, index, &val)) {
snprintf(buf, sizeof(buf), "%c", (int)val);
snprintf(buf, sizeof(buf), mode, (int)val);
}
be_pushstring(vm, buf);
break;
+3
View File
@@ -132,6 +132,9 @@ assert(string.format("%i", true) == '1')
assert(string.format("%i", false) == '0')
assert(string.format("%c", a) == '*')
# %c must honor field width and flags, like the other conversions
assert(string.format("%5c", 65) == ' A')
assert(string.format("%-5c", 65) == 'A ')
assert(string.format("%f", 3.5) == '3.500000')
assert(string.format("%f", 3) == '3.000000')