natsort

package
v1.1.10 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2024 License: Apache-2.0, MIT Imports: 1 Imported by: 0

README

natsort

This is a fork of the sortorder package of github.com/fvbommel/util.

License

  • MIT
    • the original implementation of sortorder was released by Frits van Bommel under an MIT license.
  • Public domain
    • any changes made in this fork are released into the public domain.

Documentation

Overview

Package natsort implements natural sort. In "Natural Sort Order" integers embedded in strings are compared by value.

References:

https://blog.codinghorror.com/sorting-for-humans-natural-sort-order/

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Less

func Less(str1, str2 string) bool

Less compares two strings using natural ordering.

This means that e.g. "abc2" < "abc12".

Non-digit sequences and numbers are compared separately. The former are compared bytewise, while the latter are compared numerically (except that the number of leading zeros is used as a tie-breaker). E.g. "2" < "02", "1b" > "1ax", ...

Limitation: only ASCII digits (0-9) are considered.

func Strings

func Strings(a []string)

Strings sorts the given slice of strings in natural order.

Types

type Order

type Order []string

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

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

Limitation: only ASCII digits (0-9) are considered.

func (Order) Len

func (n Order) Len() int

func (Order) Less

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

func (Order) Swap

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

Jump to

Keyboard shortcuts

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