collate

package
v0.0.0-...-26bed2b Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2014 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Overview

Package collate contains types for comparing and sorting Unicode strings according to a given collation order. Package locale provides a high-level interface to collation. Users should typically use that package instead.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Supported

func Supported() []language.Tag

Supported returns the list of languages for which collating differs from its parent.

Types

type AlternateHandling

type AlternateHandling int

AlternateHandling identifies the various ways in which variables are handled. A rune with a primary weight lower than the variable top is considered a variable. See http://www.unicode.org/reports/tr10/#Variable_Weighting for details.

const (
	// AltNonIgnorable turns off special handling of variables.
	AltNonIgnorable AlternateHandling = iota

	// AltBlanked sets variables and all subsequent primary ignorables to be
	// ignorable at all levels. This is identical to removing all variables
	// and subsequent primary ignorables from the input.
	AltBlanked

	// AltShifted sets variables to be ignorable for levels one through three and
	// adds a fourth level based on the values of the ignored levels.
	AltShifted

	// AltShiftTrimmed is a slight variant of AltShifted that is used to
	// emulate POSIX.
	AltShiftTrimmed
)

type Buffer

type Buffer struct {
	// contains filtered or unexported fields
}

Buffer holds keys generated by Key and KeyString.

func (*Buffer) Reset

func (b *Buffer) Reset()

Reset clears the buffer from previous results generated by Key and KeyString.

type Collator

type Collator struct {

	// Strength sets the maximum level to use in comparison.
	Strength colltab.Level

	// Alternate specifies an alternative handling of variables.
	Alternate AlternateHandling

	// Backwards specifies the order of sorting at the secondary level.
	// This option exists predominantly to support reverse sorting of accents in French.
	Backwards bool

	// TODO: implement:
	// With HiraganaQuaternary enabled, Hiragana codepoints will get lower values
	// than all the other non-variable code points. Strength must be greater or
	// equal to Quaternary for this to take effect.
	HiraganaQuaternary bool

	// If CaseLevel is true, a level consisting only of case characteristics will
	// be inserted in front of the tertiary level.  To ignore accents but take
	// cases into account, set Strength to Primary and CaseLevel to true.
	CaseLevel bool

	// If Numeric is true, any sequence of decimal digits (category is Nd) is sorted
	// at a primary level with its numeric value.  For example, "A-21" < "A-123".
	Numeric bool
	// contains filtered or unexported fields
}

Collator provides functionality for comparing strings for a given collation order.

func New

func New(t language.Tag) *Collator

New returns a new Collator initialized for the given locale.

func NewFromTable

func NewFromTable(t colltab.Weigher) *Collator

func (*Collator) Compare

func (c *Collator) Compare(a, b []byte) int

Compare returns an integer comparing the two byte slices. The result will be 0 if a==b, -1 if a < b, and +1 if a > b.

func (*Collator) CompareString

func (c *Collator) CompareString(a, b string) int

CompareString returns an integer comparing the two strings. The result will be 0 if a==b, -1 if a < b, and +1 if a > b.

func (*Collator) Key

func (c *Collator) Key(buf *Buffer, str []byte) []byte

Key returns the collation key for str. Passing the buffer buf may avoid memory allocations. The returned slice will point to an allocation in Buffer and will remain valid until the next call to buf.Reset().

func (*Collator) KeyFromString

func (c *Collator) KeyFromString(buf *Buffer, str string) []byte

KeyFromString returns the collation key for str. Passing the buffer buf may avoid memory allocations. The returned slice will point to an allocation in Buffer and will retain valid until the next call to buf.ResetKeys().

func (*Collator) SetOptions

func (c *Collator) SetOptions(o Option)

SetOptions accepts a Options or-ed together. All previous calls to SetOptions are ignored.

func (*Collator) Sort

func (c *Collator) Sort(x Lister)

Sort uses sort.Sort to sort the strings represented by x using the rules of c.

func (*Collator) SortStrings

func (c *Collator) SortStrings(x []string)

SortStrings uses sort.Sort to sort the strings in x using the rules of c.

type Lister

type Lister interface {
	Len() int
	Swap(i, j int)
	// Bytes returns the bytes of the text at index i.
	Bytes(i int) []byte
}

A Lister can be sorted by Collator's Sort method.

type Option

type Option int

An Option is used to change the behavior of Collator. They override the settings passed through the locale identifier.

const (
	Numeric          Option = 1 << iota // Sort numbers numerically ("2" < "12").
	IgnoreCase                          // Case-insensitive search.
	IgnoreDiacritics                    // Ignore diacritical marks. ("o" == "ö").
	IgnoreWidth                         // Ignore full versus normal width.
	UpperFirst                          // Sort upper case before lower case.
	LowerFirst                          // Sort lower case before upper case.
	Force                               // Force ordering if strings are equivalent but not equal.

	Loose = IgnoreDiacritics | IgnoreWidth | IgnoreCase
)

Directories

Path Synopsis
tools
colcmp command

Jump to

Keyboard shortcuts

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