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:
@@ -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 {
|
||||
|
Reference in New Issue
Block a user