[fmt] fix zero-padding behaviour of numbers

- when formatting a negative number with left zero-padding we expect the
  padding to be placed between the minus (-) sign and the number
- currently the padding is placed before the sign
This commit is contained in:
finn
2023-06-01 11:10:46 +02:00
parent 788f3c22bf
commit 6952124988

View File

@@ -1142,6 +1142,11 @@ _pad :: proc(fi: ^Info, s: string) {
if fi.minus { // right pad
io.write_string(fi.writer, s, &fi.n)
fmt_write_padding(fi, width)
} else if !fi.space && s != "" && s[0] == '-' {
// left pad accounting for zero pad of negative number
io.write_byte(fi.writer, '-', &fi.n)
fmt_write_padding(fi, width)
io.write_string(fi.writer, s[1:], &fi.n)
} else { // left pad
fmt_write_padding(fi, width)
io.write_string(fi.writer, s, &fi.n)