You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

30 lines
853 B

  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. package language
  5. // CompactCoreInfo is a compact integer with the three core tags encoded.
  6. type CompactCoreInfo uint32
  7. // GetCompactCore generates a uint32 value that is guaranteed to be unique for
  8. // different language, region, and script values.
  9. func GetCompactCore(t Tag) (cci CompactCoreInfo, ok bool) {
  10. if t.LangID > langNoIndexOffset {
  11. return 0, false
  12. }
  13. cci |= CompactCoreInfo(t.LangID) << (8 + 12)
  14. cci |= CompactCoreInfo(t.ScriptID) << 12
  15. cci |= CompactCoreInfo(t.RegionID)
  16. return cci, true
  17. }
  18. // Tag generates a tag from c.
  19. func (c CompactCoreInfo) Tag() Tag {
  20. return Tag{
  21. LangID: Language(c >> 20),
  22. RegionID: Region(c & 0x3ff),
  23. ScriptID: Script(c>>12) & 0xff,
  24. }
  25. }