Documentation
¶
Overview ¶
Package sortorder implements sort orders and comparison functions.
Currently, it only implements so-called "natural order", where integers embedded in strings are compared by value.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NaturalCompare ¶ added in v1.2.0
NaturalCompare compares str1 and str2 using the same natural ordering as NaturalLess. It returns a negative value if str1 sorts before str2, a positive value if str1 sorts after str2, and zero if str1 and str2 are equal.
NaturalCompare is suitable for APIs that accept a three-way comparison function, such as slices.SortFunc and slices.SortStableFunc.
func NaturalLess ¶
NaturalLess compares two strings using natural ordering. This means that e.g. "abc2" < "abc12".
Non-digit sequences and numbers are compared separately. The former are compared bytewise, while digits are compared numerically (except that the number of leading zeros is used as a tie-breaker, so e.g. "2" < "02")
Limitation: only ASCII digits (0-9) are considered.
Types ¶
type Natural ¶
type Natural []string
Natural implements sort.Interface to sort strings in natural order. This means that e.g. "abc2" < "abc12".
Non-digit sequences and numbers are compared separately. The former are compared bytewise, while digits are compared numerically (except that the number of leading zeros is used as a tie-breaker, so e.g. "2" < "02")
Limitation: only ASCII digits (0-9) are considered.