...
1
2
3
4
5
6
7
8
9
10
11
12
13
14 package compact
15
16 import (
17 "sort"
18 "strings"
19
20 "golang.org/x/text/internal/language"
21 )
22
23
24 type ID uint16
25
26 func getCoreIndex(t language.Tag) (id ID, ok bool) {
27 cci, ok := language.GetCompactCore(t)
28 if !ok {
29 return 0, false
30 }
31 i := sort.Search(len(coreTags), func(i int) bool {
32 return cci <= coreTags[i]
33 })
34 if i == len(coreTags) || coreTags[i] != cci {
35 return 0, false
36 }
37 return ID(i), true
38 }
39
40
41 func (id ID) Parent() ID {
42 return parents[id]
43 }
44
45
46 func (id ID) Tag() language.Tag {
47 if int(id) >= len(coreTags) {
48 return specialTags[int(id)-len(coreTags)]
49 }
50 return coreTags[id].Tag()
51 }
52
53 var specialTags []language.Tag
54
55 func init() {
56 tags := strings.Split(specialTagsStr, " ")
57 specialTags = make([]language.Tag, len(tags))
58 for i, t := range tags {
59 specialTags[i] = language.MustParse(t)
60 }
61 }
62
View as plain text