summaryrefslogtreecommitdiff
path: root/libgo/go/fmt/format.go
diff options
context:
space:
mode:
Diffstat (limited to 'libgo/go/fmt/format.go')
-rw-r--r--libgo/go/fmt/format.go25
1 files changed, 18 insertions, 7 deletions
diff --git a/libgo/go/fmt/format.go b/libgo/go/fmt/format.go
index 4d97d1443ed..517b18f7d43 100644
--- a/libgo/go/fmt/format.go
+++ b/libgo/go/fmt/format.go
@@ -162,24 +162,35 @@ func (f *fmt) integer(a int64, base uint64, signedness bool, digits string) {
return
}
+ negative := signedness == signed && a < 0
+ if negative {
+ a = -a
+ }
+
var buf []byte = f.intbuf[0:]
- if f.widPresent {
- width := f.wid
+ if f.widPresent || f.precPresent || f.plus || f.space {
+ width := f.wid + f.prec // Only one will be set, both are positive; this provides the maximum.
if base == 16 && f.sharp {
// Also adds "0x".
width += 2
}
+ if f.unicode {
+ // Also adds "U+".
+ width += 2
+ if f.uniQuote {
+ // Also adds " 'x'".
+ width += 1 + 1 + utf8.UTFMax + 1
+ }
+ }
+ if negative || f.plus || f.space {
+ width++
+ }
if width > nByte {
// We're going to need a bigger boat.
buf = make([]byte, width)
}
}
- negative := signedness == signed && a < 0
- if negative {
- a = -a
- }
-
// two ways to ask for extra leading zero digits: %.3d or %03d.
// apparently the first cancels the second.
prec := 0