summaryrefslogtreecommitdiffstats
path: root/vendor/golang.org/x/text/internal/number/pattern.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/golang.org/x/text/internal/number/pattern.go')
-rw-r--r--vendor/golang.org/x/text/internal/number/pattern.go33
1 files changed, 25 insertions, 8 deletions
diff --git a/vendor/golang.org/x/text/internal/number/pattern.go b/vendor/golang.org/x/text/internal/number/pattern.go
index 5610c6026..ef7f087fe 100644
--- a/vendor/golang.org/x/text/internal/number/pattern.go
+++ b/vendor/golang.org/x/text/internal/number/pattern.go
@@ -46,16 +46,17 @@ type Pattern struct {
Offset uint16 // Offset into Affix for prefix and suffix
NegOffset uint16 // Offset into Affix for negative prefix and suffix or 0.
- Multiplier uint32
+ FormatWidth uint16
+
RoundIncrement uint32 // Use Min*Digits to determine scale
PadRune rune
-
- FormatWidth uint16
+ DigitShift uint8 // Number of decimals to shift. Used for % and ‰.
GroupingSize [2]uint8
Flags PatternFlag
// Number of digits.
+ // TODO: consider using uint32
MinIntegerDigits uint8
MaxIntegerDigits uint8
MinFractionDigits uint8
@@ -90,6 +91,7 @@ type PatternFlag uint8
const (
AlwaysSign PatternFlag = 1 << iota
+ ElideSign // Use space instead of plus sign. AlwaysSign must be true.
AlwaysExpSign
AlwaysDecimalSeparator
ParenthesisForNegative // Common pattern. Saves space.
@@ -247,26 +249,41 @@ func (p *parser) affix(r rune) state {
'#', '@', '.', '*', ',', ';':
return nil
case '\'':
- return p.escape
+ p.FormatWidth--
+ return p.escapeFirst
case '%':
- if p.Multiplier != 0 {
+ if p.DigitShift != 0 {
p.setError(errDuplicatePercentSign)
}
- p.Multiplier = 100
+ p.DigitShift = 2
case '\u2030': // ‰ Per mille
- if p.Multiplier != 0 {
+ if p.DigitShift != 0 {
p.setError(errDuplicatePermilleSign)
}
- p.Multiplier = 1000
+ p.DigitShift = 3
// TODO: handle currency somehow: ¤, ¤¤, ¤¤¤, ¤¤¤¤
}
p.buf = append(p.buf, string(r)...)
return p.affix
}
+func (p *parser) escapeFirst(r rune) state {
+ switch r {
+ case '\'':
+ p.buf = append(p.buf, "\\'"...)
+ return p.affix
+ default:
+ p.buf = append(p.buf, '\'')
+ p.buf = append(p.buf, string(r)...)
+ }
+ return p.escape
+}
+
func (p *parser) escape(r rune) state {
switch r {
case '\'':
+ p.FormatWidth--
+ p.buf = append(p.buf, '\'')
return p.affix
default:
p.buf = append(p.buf, string(r)...)