mirror of
https://github.com/arendst/Tasmota.git
synced 2026-10-27 06:22:25 +00:00
Berry format support width for %c format (#25122)
This commit is contained in:
1 parent
84b011242c
commit
e2a665dfca
3 files changed
+8
-2
No files matched your search
@@ -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)
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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')
|
||||
|
||||
Reference in new issue
Block a user