build

package
v0.14.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 26, 2024 License: BSD-3-Clause Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Builder

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

func NewBuilder() *Builder

NewBuilder returns a new Builder.

func (*Builder) Add

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

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

Build builds the root Collator.

func (*Builder) Print

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

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

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

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

Build builds a Collator for Tailoring t.

func (*Tailoring) Insert

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.SetAnchor("z")
t.Insert(colltab.Primary, "ä", "")

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

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

or

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

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

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

Order "b" before "a":

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

Order "0" after the last primary ignorable:

t.SetAnchor("<last_primary_ignorable/>")
t.Insert(colltab.Primary, "0", "")

func (*Tailoring) SetAnchor

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

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

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL