Debian Codegraph @

internal/language/compact/compact.go

raw symbols SCIP
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.
4
5 // Package compact defines a compact representation of language tags.
6 //
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.)
11 //
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 compactscip-go gomod golang.org/x/text . `golang.org/x/text/internal/language/compact`/ // import "golang.org/x/text/internal/language/compact"
15
16 import (
17 "sortscip-go gomod github.com/golang/go/src go1.25.0 sort/"
18 "stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/"
19
20 "golang.org/x/text/internal/languagescip-go gomod golang.org/x/text . `golang.org/x/text/internal/language`/"
21 )
22
23 // ID is an integer identifying a single tag.
24 type IDscip-go gomod golang.org/x/text . `golang.org/x/text/internal/language/compact`/ID# uint16
25
26 func getCoreIndexscip-go gomod golang.org/x/text . `golang.org/x/text/internal/language/compact`/getCoreIndex().(t languagescip-go gomod golang.org/x/text . `golang.org/x/text/internal/language`/.Tagscip-go gomod golang.org/x/text . `golang.org/x/text/internal/language`/Tag#) (id IDscip-go gomod golang.org/x/text . `golang.org/x/text/internal/language/compact`/ID#, ok bool) {
27 cci, ok := languagescip-go gomod golang.org/x/text . `golang.org/x/text/internal/language`/.GetCompactCorescip-go gomod golang.org/x/text . `golang.org/x/text/internal/language`/GetCompactCore().(t)
28 if !ok {
29 return 0, false
30 }
31 i := sortscip-go gomod github.com/golang/go/src go1.25.0 sort/.Searchscip-go gomod github.com/golang/go/src go1.25.0 sort/Search().(len(coreTagsscip-go gomod golang.org/x/text . `golang.org/x/text/internal/language/compact`/coreTags.), func(i int) bool {
32 return cci <= coreTagsscip-go gomod golang.org/x/text . `golang.org/x/text/internal/language/compact`/coreTags.[i]
33 })
34 if i == len(coreTagsscip-go gomod golang.org/x/text . `golang.org/x/text/internal/language/compact`/coreTags.) || coreTagsscip-go gomod golang.org/x/text . `golang.org/x/text/internal/language/compact`/coreTags.[i] != cci {
35 return 0, false
36 }
37 return IDscip-go gomod golang.org/x/text . `golang.org/x/text/internal/language/compact`/ID#(i), true
38 }
39
40 // Parent returns the ID of the parent or the root ID if id is already the root.
41 func (id IDscip-go gomod golang.org/x/text . `golang.org/x/text/internal/language/compact`/ID#) Parentscip-go gomod golang.org/x/text . `golang.org/x/text/internal/language/compact`/ID#Parent().() IDscip-go gomod golang.org/x/text . `golang.org/x/text/internal/language/compact`/ID# {
42 return parentsscip-go gomod golang.org/x/text . `golang.org/x/text/internal/language/compact`/parents.[id]
43 }
44
45 // Tag converts id to an internal language Tag.
46 func (id IDscip-go gomod golang.org/x/text . `golang.org/x/text/internal/language/compact`/ID#) Tagscip-go gomod golang.org/x/text . `golang.org/x/text/internal/language/compact`/ID#Tag().() languagescip-go gomod golang.org/x/text . `golang.org/x/text/internal/language`/.Tagscip-go gomod golang.org/x/text . `golang.org/x/text/internal/language`/Tag# {
47 if int(id) >= len(coreTagsscip-go gomod golang.org/x/text . `golang.org/x/text/internal/language/compact`/coreTags.) {
48 return specialTagsscip-go gomod golang.org/x/text . `golang.org/x/text/internal/language/compact`/specialTags.[int(id)-len(coreTagsscip-go gomod golang.org/x/text . `golang.org/x/text/internal/language/compact`/coreTags.)]
49 }
50 return coreTagsscip-go gomod golang.org/x/text . `golang.org/x/text/internal/language/compact`/coreTags.[id].Tagscip-go gomod golang.org/x/text . `golang.org/x/text/internal/language`/CompactCoreInfo#Tag().()
51 }
52
53 var specialTagsscip-go gomod golang.org/x/text . `golang.org/x/text/internal/language/compact`/specialTags. []languagescip-go gomod golang.org/x/text . `golang.org/x/text/internal/language`/.Tagscip-go gomod golang.org/x/text . `golang.org/x/text/internal/language`/Tag#
54
55 func initscip-go gomod golang.org/x/text . `golang.org/x/text/internal/language/compact`/init().() {
56 tags := stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.Splitscip-go gomod github.com/golang/go/src go1.25.0 strings/Split().(specialTagsStrscip-go gomod golang.org/x/text . `golang.org/x/text/internal/language/compact`/specialTagsStr., " ")
57 specialTagsscip-go gomod golang.org/x/text . `golang.org/x/text/internal/language/compact`/specialTags. = make([]languagescip-go gomod golang.org/x/text . `golang.org/x/text/internal/language`/.Tagscip-go gomod golang.org/x/text . `golang.org/x/text/internal/language`/Tag#, len(tags))
58 for i, t := range tags {
59 specialTagsscip-go gomod golang.org/x/text . `golang.org/x/text/internal/language/compact`/specialTags.[i] = languagescip-go gomod golang.org/x/text . `golang.org/x/text/internal/language`/.MustParsescip-go gomod golang.org/x/text . `golang.org/x/text/internal/language`/MustParse().(t)
60 }
61 }