From b84736e9b6401df0c6eeab9950bef09458a6aefd Mon Sep 17 00:00:00 2001 From: Christopher Speller Date: Fri, 29 Sep 2017 12:46:30 -0700 Subject: Updating server dependancies. (#7538) --- vendor/golang.org/x/text/feature/plural/plural.go | 34 +++++++++++++++++++---- 1 file changed, 29 insertions(+), 5 deletions(-) (limited to 'vendor/golang.org/x/text/feature/plural/plural.go') diff --git a/vendor/golang.org/x/text/feature/plural/plural.go b/vendor/golang.org/x/text/feature/plural/plural.go index 2b4cfe321..61faf187d 100644 --- a/vendor/golang.org/x/text/feature/plural/plural.go +++ b/vendor/golang.org/x/text/feature/plural/plural.go @@ -13,6 +13,7 @@ package plural import ( + "golang.org/x/text/internal/number" "golang.org/x/text/language" ) @@ -109,21 +110,25 @@ func getIntApprox(digits []byte, start, end, nMod, big int) (n int) { // 123 []byte{1, 2, 3} 3 0 // 123.4 []byte{1, 2, 3, 4} 3 1 // 123.40 []byte{1, 2, 3, 4} 3 2 -// 100000 []byte{1} 6......0 -// 100000.00 []byte{1} 6......3 +// 100000 []byte{1} 6 0 +// 100000.00 []byte{1} 6 3 func (p *Rules) MatchDigits(t language.Tag, digits []byte, exp, scale int) Form { index, _ := language.CompactIndex(t) - endN := len(digits) + exp // Differentiate up to including mod 1000000 for the integer part. - n := getIntApprox(digits, 0, endN, 6, 1000000) + n := getIntApprox(digits, 0, exp, 6, 1000000) // Differentiate up to including mod 100 for the fractional part. - f := getIntApprox(digits, endN, endN+scale, 2, 100) + f := getIntApprox(digits, exp, exp+scale, 2, 100) return matchPlural(p, index, n, f, scale) } +func (p *Rules) matchDisplayDigits(t language.Tag, d *number.Digits) (Form, int) { + n := getIntApprox(d.Digits, 0, int(d.Exp), 6, 1000000) + return p.MatchDigits(t, d.Digits, int(d.Exp), d.NumFracDigits()), n +} + func validForms(p *Rules, t language.Tag) (forms []Form) { index, _ := language.CompactIndex(t) offset := p.langToIndex[index] @@ -145,6 +150,25 @@ func (p *Rules) matchComponents(t language.Tag, n, f, scale int) Form { return matchPlural(p, index, n, f, scale) } +// MatchPlural returns the plural form for the given language and plural +// operands (as defined in +// http://unicode.org/reports/tr35/tr35-numbers.html#Language_Plural_Rules): +// where +// n absolute value of the source number (integer and decimals) +// input +// i integer digits of n. +// v number of visible fraction digits in n, with trailing zeros. +// w number of visible fraction digits in n, without trailing zeros. +// f visible fractional digits in n, with trailing zeros (f = t * 10^(v-w)) +// t visible fractional digits in n, without trailing zeros. +// +// If any of the operand values is too large to fit in an int, it is okay to +// pass the value modulo 10,000,000. +func (p *Rules) MatchPlural(lang language.Tag, i, v, w, f, t int) Form { + index, _ := language.CompactIndex(lang) + return matchPlural(p, index, i, f, v) +} + func matchPlural(p *Rules, index int, n, f, v int) Form { nMask := p.inclusionMasks[n%maxMod] // Compute the fMask inline in the rules below, as it is relatively rare. -- cgit v1.2.3-1-g7c22