natsort

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2019 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Overview

natsort implements Martin Pool's Natural Order String Comparison Original implementation: https://github.com/sourcefrog/natsort

Strings are sorted as usual, except that decimal integer substrings are compared on their numeric value. For example:

a < a0 < a1 < a1a < a1b < a2 < a10 < a20

All white space and control characters are ignored.

Leading zeros are *not* ignored, which tends to give more reasonable results on decimal fractions:

1.001 < 1.002 < 1.010 < 1.02 < 1.1 < 1.3

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Compare

func Compare(a, b string) int

Compare tests if a is less than, equal to, or greater than b according to the natural sorting algorithm, returning -1, 0, or +1 respectively.

func Less

func Less(a, b string) bool

Less determines if a naturally comes before b. Unlike Compare it will fall back to a normal string comparison which considers spaces if the two would otherwise be equal. That helps ensure the stability of sorts.

func Strings

func Strings(s []string)

Strings natural sorts a slice of strings.

func StringsAreSorted

func StringsAreSorted(s []string) bool

StringsAreSorted tests whether a slice of strings is natural sorted.

Types

This section is empty.

Jump to

Keyboard shortcuts

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