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