Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
kardolus
GitHub Repository: kardolus/chatgpt-cli
Path: blob/main/vendor/golang.org/x/text/internal/language/compact.go
2893 views
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 language
6
7
// CompactCoreInfo is a compact integer with the three core tags encoded.
8
type CompactCoreInfo uint32
9
10
// GetCompactCore generates a uint32 value that is guaranteed to be unique for
11
// different language, region, and script values.
12
func GetCompactCore(t Tag) (cci CompactCoreInfo, ok bool) {
13
if t.LangID > langNoIndexOffset {
14
return 0, false
15
}
16
cci |= CompactCoreInfo(t.LangID) << (8 + 12)
17
cci |= CompactCoreInfo(t.ScriptID) << 12
18
cci |= CompactCoreInfo(t.RegionID)
19
return cci, true
20
}
21
22
// Tag generates a tag from c.
23
func (c CompactCoreInfo) Tag() Tag {
24
return Tag{
25
LangID: Language(c >> 20),
26
RegionID: Region(c & 0x3ff),
27
ScriptID: Script(c>>12) & 0xff,
28
}
29
}
30
31