export_test.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // Copyright 2012 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 collate
  5. // Export for testing.
  6. // TODO: no longer necessary. Remove at some point.
  7. import (
  8. "fmt"
  9. "golang.org/x/text/internal/colltab"
  10. )
  11. const (
  12. defaultSecondary = 0x20
  13. defaultTertiary = 0x2
  14. )
  15. type Weights struct {
  16. Primary, Secondary, Tertiary, Quaternary int
  17. }
  18. func W(ce ...int) Weights {
  19. w := Weights{ce[0], defaultSecondary, defaultTertiary, 0}
  20. if len(ce) > 1 {
  21. w.Secondary = ce[1]
  22. }
  23. if len(ce) > 2 {
  24. w.Tertiary = ce[2]
  25. }
  26. if len(ce) > 3 {
  27. w.Quaternary = ce[3]
  28. }
  29. return w
  30. }
  31. func (w Weights) String() string {
  32. return fmt.Sprintf("[%X.%X.%X.%X]", w.Primary, w.Secondary, w.Tertiary, w.Quaternary)
  33. }
  34. func convertFromWeights(ws []Weights) []colltab.Elem {
  35. out := make([]colltab.Elem, len(ws))
  36. for i, w := range ws {
  37. out[i], _ = colltab.MakeElem(w.Primary, w.Secondary, w.Tertiary, 0)
  38. if out[i] == colltab.Ignore && w.Quaternary > 0 {
  39. out[i] = colltab.MakeQuaternary(w.Quaternary)
  40. }
  41. }
  42. return out
  43. }