Debian Codegraph @

debian/go/src/github.com/gohugoio/go-i18n/v2/internal/plural/rule.go

raw
1 package plural
2
3 import (
4 "golang.org/x/text/language"
5 )
6
7 // Rule defines the CLDR plural rules for a language.
8 // http://www.unicode.org/cldr/charts/latest/supplemental/language_plural_rules.html
9 // http://unicode.org/reports/tr35/tr35-numbers.html#Operands
10 type Rule struct {
11 PluralForms map[Form]struct{}
12 PluralFormFunc func(*Operands) Form
13 }
14
15 func addPluralRules(rules Rules, ids []string, ps *Rule) {
16 for _, id := range ids {
17 if id == "root" {
18 continue
19 }
20 tag := language.MustParse(id)
21 rules[tag] = ps
22 }
23 }
24
25 func newPluralFormSet(pluralForms ...Form) map[Form]struct{} {
26 set := make(map[Form]struct{}, len(pluralForms))
27 for _, plural := range pluralForms {
28 set[plural] = struct{}{}
29 }
30 return set
31 }
32
33 func intInRange(i, from, to int64) bool {
34 return from <= i && i <= to
35 }
36
37 func intEqualsAny(i int64, any ...int64) bool {
38 for _, a := range any {
39 if i == a {
40 return true
41 }
42 }
43 return false
44 }