Help us shape the future of Go! Take the 2026 Go Developer Survey

natural

package
v0.13.1 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2026 License: Apache-2.0 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