text: golang.org/x/text/collate/build Index | Files

package build

import "golang.org/x/text/collate/build"


Package Files

builder.go colelem.go contract.go order.go table.go trie.go

type Builder Uses

type Builder struct {
    // contains filtered or unexported fields

A Builder builds a root collation table. The user must specify the collation elements for each entry. A common use will be to base the weights on those specified in the allkeys* file as provided by the UCA or CLDR.

func NewBuilder Uses

func NewBuilder() *Builder

NewBuilder returns a new Builder.

func (*Builder) Add Uses

func (b *Builder) Add(runes []rune, colelems [][]int, variables []int) error

Add adds an entry to the collation element table, mapping a slice of runes to a sequence of collation elements. A collation element is specified as list of weights: []int{primary, secondary, ...}. The entries are typically obtained from a collation element table as defined in https://www.unicode.org/reports/tr10/#Data_Table_Format. Note that the collation elements specified by colelems are only used as a guide. The actual weights generated by Builder may differ. The argument variables is a list of indices into colelems that should contain a value for each colelem that is a variable. (See the reference above.)

func (*Builder) Build Uses

func (b *Builder) Build() (colltab.Weighter, error)

Build builds the root Collator.

func (*Builder) Print Uses

func (b *Builder) Print(w io.Writer) (n int, err error)

Print prints the tables for b and all its Tailorings as a Go file that can be included in the Collate package.

func (*Builder) Tailoring Uses

func (b *Builder) Tailoring(loc language.Tag) *Tailoring

Tailoring returns a Tailoring for the given locale. One should have completed all calls to Add before calling Tailoring.

type Tailoring Uses

type Tailoring struct {
    // contains filtered or unexported fields

A Tailoring builds a collation table based on another collation table. The table is defined by specifying tailorings to the underlying table. See https://unicode.org/reports/tr35/ for an overview of tailoring collation tables. The CLDR contains pre-defined tailorings for a variety of languages (See https://www.unicode.org/Public/cldr/<version>/core.zip.)

func (*Tailoring) Build Uses

func (t *Tailoring) Build() (colltab.Weighter, error)

Build builds a Collator for Tailoring t.

func (*Tailoring) Insert Uses

func (t *Tailoring) Insert(level colltab.Level, str, extend string) error

Insert sets the ordering of str relative to the entry set by the previous call to SetAnchor or Insert. The argument extend corresponds to the extend elements as defined in LDML. A non-empty value for extend will cause the collation elements corresponding to extend to be appended to the collation elements generated for the entry added by Insert. This has the same net effect as sorting str after the string anchor+extend. See https://www.unicode.org/reports/tr10/#Tailoring_Example for details on parametric tailoring and https://unicode.org/reports/tr35/#Collation_Elements for full details on LDML.

Examples: create a tailoring for Swedish, where "ä" is ordered after "z" at the primary sorting level:

     t := b.Tailoring("se")
		t.Insert(colltab.Primary, "ä", "")

Order "ü" after "ue" at the secondary sorting level:

t.Insert(colltab.Secondary, "ü","")


t.Insert(colltab.Secondary, "ü", "e")

Order "q" afer "ab" at the secondary level and "Q" after "q" at the tertiary level:

t.Insert(colltab.Secondary, "q", "")
t.Insert(colltab.Tertiary, "Q", "")

Order "b" before "a":

t.Insert(colltab.Primary, "b", "")

Order "0" after the last primary ignorable:

t.Insert(colltab.Primary, "0", "")

func (*Tailoring) SetAnchor Uses

func (t *Tailoring) SetAnchor(anchor string) error

SetAnchor sets the point after which elements passed in subsequent calls to Insert will be inserted. It is equivalent to the reset directive in an LDML specification. See Insert for an example. SetAnchor supports the following logical reset positions: <first_tertiary_ignorable/>, <last_teriary_ignorable/>, <first_primary_ignorable/>, and <last_non_ignorable/>.

func (*Tailoring) SetAnchorBefore Uses

func (t *Tailoring) SetAnchorBefore(anchor string) error

SetAnchorBefore is similar to SetAnchor, except that subsequent calls to Insert will insert entries before the anchor.

Package build imports 12 packages (graph). Updated 2020-12-11. Refresh now. Tools for package owners.