Example #1
0
// New returns a new Matcher for the given language and options.
func New(t language.Tag, opts ...Option) *Matcher {
	m := &Matcher{
		w: colltab.Init(locales[newcolltab.MatchLang(t, tags)]),
	}
	for _, f := range opts {
		f(m)
	}
	return m
}
Example #2
0
// Build builds the root Collator.
// TODO: return Weighter instead
func (b *Builder) Build() (colltab.Weighter, error) {
	t, err := b.build()
	if err != nil {
		return nil, err
	}
	table := colltab.Init(t)
	if table == nil {
		panic("generated table of incompatible type")
	}
	return table, nil
}
Example #3
0
// New returns a new Collator initialized for the given locale.
func New(t language.Tag, o ...Option) *Collator {
	index := newcolltab.MatchLang(t, tags)
	c := newCollator(colltab.Init(locales[index]))

	// Set options from the user-supplied tag.
	c.setFromTag(t)

	// Set the user-supplied options.
	c.setOptions(o)

	c.init()
	return c
}
Example #4
0
// New returns a new Collator initialized for the given locale.
func New(t language.Tag, o ...Option) *Collator {
	tt, index, _ := matcher.Match(t)
	c := newCollator(colltab.Init(locales[index]))

	// Set the default options for the retrieved locale.
	c.setFromTag(tt)

	// Set options from the user-supplied tag.
	c.setFromTag(t)

	// Set the user-supplied options.
	c.setOptions(o)

	return c
}
Example #5
0
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package collate

import (
	"reflect"
	"strings"
	"testing"

	"golang.org/x/text/collate/colltab"
	"golang.org/x/text/language"
)

var (
	defaultIgnore = ignore(colltab.Tertiary)
	defaultTable  = colltab.Init(locales[0])
)

func TestOptions(t *testing.T) {
	for i, tt := range []struct {
		in  []Option
		out options
	}{
		0: {
			out: options{
				ignore: defaultIgnore,
			},
		},
		1: {
			in: []Option{IgnoreDiacritics},
			out: options{