package collate

Import Path
	golang.org/x/text/collate (on go.dev)

Dependency Relation
	imports 6 packages, and imported by one package

Involved Source Files Package collate contains types for comparing and sorting Unicode strings according to a given collation order. index.go option.go sort.go tables.go
Code Examples package main import ( "fmt" "golang.org/x/text/collate" "golang.org/x/text/language" ) type book struct { title string } type bookcase struct { books []book } func (bc bookcase) Len() int { return len(bc.books) } func (bc bookcase) Swap(i, j int) { temp := bc.books[i] bc.books[i] = bc.books[j] bc.books[j] = temp } func (bc bookcase) Bytes(i int) []byte { // returns the bytes of text at index i return []byte(bc.books[i].title) } func main() { bc := bookcase{ books: []book{ {title: "If Cats Disappeared from the World"}, {title: "The Guest Cat"}, {title: "Catwings"}, }, } cc := collate.New(language.English) cc.Sort(bc) for _, b := range bc.books { fmt.Println(b.title) } }
Package-Level Type Names (total 4)
/* sort by: | */
Buffer holds keys generated by Key and KeyString. Reset clears the buffer from previous results generated by Key and KeyString. func (*Collator).Key(buf *Buffer, str []byte) []byte func (*Collator).KeyFromString(buf *Buffer, str string) []byte
Collator provides functionality for comparing strings for a given collation order. 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. 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. 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(). 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(). Sort uses sort.Sort to sort the strings represented by x using the rules of c. SortStrings uses sort.Sort to sort the strings in x using the rules of c. func New(t language.Tag, o ...Option) *Collator func NewFromTable(w colltab.Weighter, o ...Option) *Collator
A Lister can be sorted by Collator's Sort method. Bytes returns the bytes of the text at index i. ( Lister) Len() int ( Lister) Swap(i, j int) func (*Collator).Sort(x Lister)
An Option is used to change the behavior of a Collator. Options override the settings passed through the locale identifier. func OptionsFromTag(t language.Tag) Option func Reorder(s ...string) Option func New(t language.Tag, o ...Option) *Collator func NewFromTable(w colltab.Weighter, o ...Option) *Collator var Force var IgnoreCase var IgnoreDiacritics var IgnoreWidth var Loose var Numeric
Package-Level Functions (total 5)
New returns a new Collator initialized for the given locale.
NewFromTable returns a new Collator for the given Weighter.
OptionsFromTag extracts the BCP47 collation options from the tag and configures a collator accordingly. These options are set before any other option.
Reorder overrides the pre-defined ordering of scripts and character sets.
Supported returns the list of languages for which collating differs from its parent.
Package-Level Variables (total 6)
Force ordering if strings are equivalent but not equal.
IgnoreCase sets case-insensitive comparison.
IgnoreDiacritics causes diacritical marks to be ignored. ("o" == "รถ").
IgnoreWidth causes full-width characters to match their half-width equivalents.
Loose sets the collator to ignore diacritics, case and width.
Numeric specifies that numbers should sort numerically ("2" < "12").
Package-Level Constants (total 2)
CLDRVersion is the CLDR version from which the tables in this package are derived.
UnicodeVersion is the Unicode version from which the tables in this package are derived.