natural

package
v0.0.0-...-d29b966 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2026 License: BSD-3-Clause Imports: 2 Imported by: 0

Documentation

Overview

Package natural implements "Natural Sort Order" for strings. This allows sorting strings in a way that numbers in strings are compared numerically, rather than lexicographically.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Compare

func Compare(a, b string) int

Compare implements natural sort order for strings, where numbers inside strings are compared numerically. For example:

"uint8" < "uint16" < "uint32"

The implementation conceptually splits the string into components of digits and non-digits. Non-digit sequences are compared lexicographically. Digit sequences are compared numerically. When numeric values are equal, the one with fewer leading zeros is considered smaller. For example:

"01" < "001" < "02"

The numeric components consist only of sequences of decimal digits [0-9] denoting non-negative integers. For example:

"1e6"  < "10e5"
"0xAB" < "0xB"
"-5"   < "-10"

func Less

func Less(a, b string) bool

Less implements natural string comparison, where numbers are compared numerically.

Types

This section is empty.

Jump to

Keyboard shortcuts

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