Skip to content

Commit 6353ef0

Browse files
committed
message: use localized number formatting
This change implements default localized number formattting for base-type arguments. Tailored formatting, like engineering notation, is planned through the number package. Change-Id: I58f9c3b5543b627ab8b705a0b32819fdf317754b Reviewed-on: https://go-review.googlesource.com/46472 Run-TryBot: Marcel van Lohuizen <mpvl@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Nigel Tao <nigeltao@golang.org>
1 parent 5c8fd47 commit 6353ef0

File tree

6 files changed

+398
-140
lines changed

6 files changed

+398
-140
lines changed

internal/number/format.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,8 +454,10 @@ func appendAffix(dst []byte, f *Formatter, affix string, neg bool) []byte {
454454
case r == '-' || r == '+':
455455
if neg {
456456
dst = append(dst, f.Symbol(SymMinusSign)...)
457-
} else {
457+
} else if f.Flags&ElideSign == 0 {
458458
dst = append(dst, f.Symbol(SymPlusSign)...)
459+
} else {
460+
dst = append(dst, ' ')
459461
}
460462
default:
461463
dst = append(dst, string(r)...)

internal/number/pattern.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ type Pattern struct {
5656
Flags PatternFlag
5757

5858
// Number of digits.
59+
// TODO: consider using uint32
5960
MinIntegerDigits uint8
6061
MaxIntegerDigits uint8
6162
MinFractionDigits uint8
@@ -90,6 +91,7 @@ type PatternFlag uint8
9091

9192
const (
9293
AlwaysSign PatternFlag = 1 << iota
94+
ElideSign // Use space instead of plus sign. AlwaysSign must be true.
9395
AlwaysExpSign
9496
AlwaysDecimalSeparator
9597
ParenthesisForNegative // Common pattern. Saves space.

0 commit comments

Comments
 (0)