Incorrect justify formatting of integers.

This commit is contained in:
Christoffer Lerno
2024-08-01 01:20:42 +02:00
parent d8820259d2
commit b83d388523
3 changed files with 19 additions and 3 deletions

View File

@@ -628,15 +628,15 @@ fn usz! Formatter.out_reverse(&self, char[] buf) @private
usz buffer_start_idx = self.idx;
usz len = buf.len;
// pad spaces up to given width
if (!self.flags.zeropad)
if (!self.flags.zeropad && !self.flags.left)
{
n += self.adjust(len)!;
n += self.pad(' ', self.width, len)!;
}
// reverse string
while (len) n += self.out(buf[--len])!;
// append pad spaces up to given width
n += self.adjust(self.idx - buffer_start_idx)!;
n += self.adjust(n)!;
return n;
}

View File

@@ -27,6 +27,7 @@
- Fix incorrect linker selection on some platforms.
- Struct members declared in a single line declaration were not sharing attributes. #1266
- `opt` project setting now properly documented.
- Incorrect justify formatting of integers.
### Stdlib changes

View File

@@ -1,5 +1,20 @@
module std::io @test;
fn void printf_int()
{
String s;
s = string::new_format("[%-10d]", 78);
assert(s == "[78 ]");
s = string::new_format("[%10d]", 78);
assert(s == "[ 78]");
s = string::new_format("[%010d]", 78);
assert(s == "[0000000078]");
s = string::new_format("[%+10d]", 78);
assert(s == "[ +78]");
s = string::new_format("[%-+10d]", 78);
assert(s == "[+78 ]");
}
fn void printf_a()
{
String s;