compareNatural

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. Intended for usage in opCmp overloads.

nothrow @safe pure
int
compareNatural
(
inout char[] a
,
inout char[] b
)
out (result) { assert (result <= 1, "Result too large"); assert (result >= -1, "Result too small"); }

Return Value

Type: int

-1 if a comes before b, 0 if a and b are equal, 1 if a comes after b

Examples

struct someStruct {
    string someText;
    int opCmp(someStruct b) {
         return compareNatural(this.someText, b.someText);
    }
}

Meta