casefolded

package
v0.0.0-...-b662464 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2023 License: MIT Imports: 2 Imported by: 1

README

casefolded PkgGoDev

import "github.com/fvbommel/sortorder/casefolded"

Case-folded sort orders and comparison functions.

These sort characters as the lowest unicode value that is equivalent to that character, ignoring case.

Not all Unicode special cases are supported.

This is a separate sub-package because this needs to pull in the Unicode tables in the standard library, which can add significantly to the size of binaries.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NaturalLess

func NaturalLess(str1, str2 string) bool

NaturalLess compares two strings using natural ordering. This means that e.g. "abc2" < "abc12".

This is the simple case-folded version, which means that letters are considered equal if strings.SimpleFold says they are. For example, "abc2" < "ABC12" < "abc100" and 'k' == '\u212a' (the Kelvin symbol).

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

Limitations:

  • only ASCII digits (0-9) are considered.
  • comparisons are done on a rune-by-rune basis, so some special case equivalences like 'ß' == 'SS" are not supported.
  • Special cases like Turkish 'i' == 'İ' (and not regular dotless 'I') are not supported either.

Types

type Natural

type Natural []string

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

This is the simple case-folded version, which means that letters are considered equal if strings.SimpleFold says they are. For example, "abc2" < "ABC12" < "abc100" and 'k' == '\u212a' (the Kelvin symbol).

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

Limitations:

  • only ASCII digits (0-9) are considered.
  • comparisons are done on a rune-by-rune basis, so some special case equivalences like 'ß' == 'SS" are not supported.
  • Special cases like Turkish 'i' == 'İ' (and not regular dotless 'I') are not supported either.

func (Natural) Len

func (n Natural) Len() int

func (Natural) Less

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

func (Natural) Swap

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

Jump to

Keyboard shortcuts

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