localecompare

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Compare

func Compare(a, b string) int

Compare is `a.localeCompare(b)` under the root locale: punctuation and case are weighed as Node weighs them, `a` before `A`, accents after base letters, U+FFFD last. The collation tables are golang.org/x/text's (collate.CLDRVersion, collate.UnicodeVersion), older than Node's ICU. It is safe for concurrent use and returns -1, 0 or 1.

Types

type Collator

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

Collator compares strings as `a.localeCompare(b)` does under the root locale (see Compare). Like the collate.Collator it wraps it keeps scratch buffers, so one Collator must not be shared by goroutines.

func NewCollator

func NewCollator() *Collator

NewCollator returns a Collator that orders strings as Node's root-locale localeCompare does.

func (*Collator) CompareString

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

CompareString returns -1, 0 or 1.

Jump to

Keyboard shortcuts

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