natcmp

Natural string comparison

This module provides functions for easily sorting and comparing strings. For implementing natural comparison methods in structs, see the NaturalComparable and NaturalPathComparable templates, or the compareNatural and comparePathsNatural functions for a more manual implementation.

For sorting ranges of strings, see the compareNaturalSort and comparePathsNaturalSort functions.

Members

Functions

compareNatural
int compareNatural(T a, T b)

Compares two strings in a way that is natural to humans. Integers come before non-integers, and integers are compared as if they were numbers instead of strings of characters. Best used in opCmp overloads.

compareNaturalSort
bool compareNaturalSort(T a, T b)

Natural string comparison function for use with phobos's sorting algorithm

comparePathsNatural
int comparePathsNatural(T pathA, T pathB)

Compares path strings naturally. Comparing paths naturally requires path separators to be treated specially. Intended for usage in opCmp overloads.

comparePathsNaturalSort
bool comparePathsNaturalSort(T a, T b)

Path comparison function for use with phobos's sorting algorithm

Mixin templates

NaturalComparable
mixintemplate NaturalComparable(alias T)

Automatically generates natural-comparing opCmp, opEquals and toHash methods for a particular property or method. Methods must be @safe, nothrow, and const.

NaturalPathComparable
mixintemplate NaturalPathComparable(alias T)

Automatically generates natural-path-comparing opCmp, opEquals and toHash methods for a particular property or method. Methods must be @safe, nothrow, and const.

Meta

Authors

Cameron "Herringway" Ross