Ver Fonte

Merge pull request #2573 from inbelic/inbelic/fmt-zero-padding

[fmt] fix zero-padding behaviour of numbers
gingerBill há 2 anos atrás
pai
commit
ae7bf468d1
1 ficheiros alterados com 5 adições e 0 exclusões
  1. 5 0
      core/fmt/fmt.odin

+ 5 - 0
core/fmt/fmt.odin

@@ -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)