collate

package
v0.0.0-...-f3d8a94 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2018 License: MIT, 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.

Index

Constants

View Source
const CLDRVersion = "23"

CLDRVersion is the CLDR version from which the tables in this package are derived.

View Source
const UnicodeVersion = "6.2.0"

UnicodeVersion is the Unicode version from which the tables in this package are derived.

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 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 {
	// contains filtered or unexported fields
}

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

func New

func New(t language.Tag, o ...Option) *Collator

New returns a new Collator initialized for the given locale.

func NewFromTable

func NewFromTable(w colltab.Weighter, o ...Option) *Collator

NewFromTable returns a new Collator for the given Weighter.

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) 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 struct {
	// contains filtered or unexported fields
}

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

var (
	// IgnoreCase sets case-insensitive comparison.
	IgnoreCase Option = ignoreCase

	// IgnoreDiacritics causes diacritical marks to be ignored. ("o" == "ö").
	IgnoreDiacritics Option = ignoreDiacritics

	// IgnoreWidth causes full-width characters to match their half-width
	// equivalents.
	IgnoreWidth Option = ignoreWidth

	// Loose sets the collator to ignore diacritics, case and weight.
	Loose Option = loose

	// Force ordering if strings are equivalent but not equal.
	Force Option = force

	// Numeric specifies that numbers should sort numerically ("2" < "12").
	Numeric Option = numeric
)

func OptionsFromTag

func OptionsFromTag(t language.Tag) Option

OptionsFromTag extracts the BCP47 collation options from the tag and configures a collator accordingly. These options are set before any other option.

func Reorder

func Reorder(s ...string) Option

Reorder overrides the pre-defined ordering of scripts and character sets.

Directories

Path Synopsis
tools

Jump to

Keyboard shortcuts

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