1 // Copyright 2018 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 // Package compact defines a compact representation of language tags.
7 // Common language tags (at least all for which locale information is defined
8 // in CLDR) are assigned a unique index. Each Tag is associated with such an
9 // ID for selecting language-related resources (such as translations) as well
10 // as one for selecting regional defaults (currency, number formatting, etc.)
12 // It may want to export this functionality at some point, but at this point
13 // this is only available for use within x/text.
14 package compact // import "golang.org/x/text/internal/language/compact"
20 "golang.org/x/text/internal/language"
23 // ID is an integer identifying a single tag.
26 func getCoreIndex(t language.Tag) (id ID, ok bool) {
27 cci, ok := language.GetCompactCore(t)
31 i := sort.Search(len(coreTags), func(i int) bool {
32 return cci <= coreTags[i]
34 if i == len(coreTags) || coreTags[i] != cci {
40 // Parent returns the ID of the parent or the root ID if id is already the root.
41 func (id ID) Parent() ID {
45 // Tag converts id to an internal language Tag.
46 func (id ID) Tag() language.Tag {
47 if int(id) >= len(coreTags) {
48 return specialTags[int(id)-len(coreTags)]
50 return coreTags[id].Tag()
53 var specialTags []language.Tag
56 tags := strings.Split(specialTagsStr, " ")
57 specialTags = make([]language.Tag, len(tags))
58 for i, t := range tags {
59 specialTags[i] = language.MustParse(t)