1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

builtin: fix {-7:08b} (interpolation of negative numbers with 0 padding), add tests

This commit is contained in:
Delyan Angelov
2021-12-04 13:04:51 +02:00
parent 89c08c6292
commit d59aa14b26
2 changed files with 67 additions and 1 deletions

View File

@@ -256,12 +256,21 @@ fn (data &StrIntpData) process_str_intp_data(mut sb strings.Builder) {
if base == 3 {
base = 2
}
mut hx := strconv.format_int(d, base)
mut absd, mut write_minus := d, false
if d < 0 && pad_ch != ` ` {
absd = -d
write_minus = true
}
mut hx := strconv.format_int(absd, base)
if upper_case {
tmp := hx
hx = hx.to_upper()
tmp.free()
}
if write_minus {
sb.write_b(`-`)
bf.len0-- // compensate for the `-` above
}
if width == 0 {
sb.write_string(hx)
} else {