package casefolded

import "github.com/fvbommel/sortorder/casefolded"

Index

Functions

func NaturalLess

func NaturalLess(str1, str2 string) bool

NaturalLess compares two strings using natural ordering. This means that e.g. "abc2" < "abc12".

This is the simple case-folded version, which means that letters are considered equal if strings.SimpleFold says they are. For example, "abc2" < "ABC12" < "abc100" and 'k' == '\u212a' (the Kelvin symbol).

Non-digit sequences and numbers are compared separately. The former are compared rune-by-rune using the lowest equivalent runes, while digits are compared numerically (except that the number of leading zeros is used as a tie-breaker, so e.g. "2" < "02")

Limitations:

Types

type Natural

type Natural []string

Natural implements sort.Interface to sort strings in natural order. This means that e.g. "abc2" < "abc12".

This is the simple case-folded version, which means that letters are considered equal if strings.SimpleFold says they are. For example, "abc2" < "ABC12" < "abc100" and 'k' == '\u212a' (the Kelvin symbol).

Non-digit sequences and numbers are compared separately. The former are compared rune-by-rune using the lowest equivalent runes, while digits are compared numerically (except that the number of leading zeros is used as a tie-breaker, so e.g. "2" < "02")

Limitations:

func (Natural) Len

func (n Natural) Len() int

func (Natural) Less

func (n Natural) Less(i, j int) bool

func (Natural) Swap

func (n Natural) Swap(i, j int)

Source Files

natsort.go

Version
v1.1.0 (latest)
Published
Mar 18, 2023
Platform
js/wasm
Imports
2 packages
Last checked
1 week ago

Tools for package owners.