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
5package language
6
7// CompactCoreInfo is a compact integer with the three core tags encoded.
8type CompactCoreInfo uint32
9
10// GetCompactCore generates a uint32 value that is guaranteed to be unique for
11// different language, region, and script values.
12func 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.
23func (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