natsort

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: May 11, 2016 License: Apache-2.0 Imports: 1 Imported by: 3

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

type StringSlice

type StringSlice []string

StringSlice provides sort.Interface for natural sorting []string.

func (StringSlice) Len

func (ss StringSlice) Len() int

func (StringSlice) Less

func (ss StringSlice) Less(i, j int) bool

func (StringSlice) Swap

func (ss StringSlice) Swap(i, j int)

Jump to

Keyboard shortcuts

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