Each instance has either or both of a convert and a compare function. The convert function, if any, is called on each Array item exactly once prior to sorting, as preprocessing. The compare is used to compare two values (the return values of convert, if any). If no compare is defined, then the native sort comparator is used (presumably lexical String compare).
The convert may return undefined, null, or NaN to indicate something that cannot be parsed. The compare function need not test for those cases; it will not be given them.
The convert may assume that its input is a (non-null) String and is already left trimmed (via burst.Text.ltrim).
Note that the Array.sort comparator in ECMAScript is like Java and C, in that it returns a number less than, equal to, or greater than zero (like a - b
). This differs from the C++ STL, which uses a boolean less
function in its sort template.
The predefined comparators are these:
Public Member Functions | |
Comparator (String name, Function convert, Function compare) | |
The constructor. | |
Static Public Member Functions | |
getComparator (String name, Boolean missing_ok) | |
Get an burst.Comparator instance by name. | |
Number | stringCompare (String a, String b) |
An implementation of what (we believe) the native Array.sort does for String comparison when the sort function is not provided. |
|
The constructor. It automatically registers the instance using the name.
|
|
Get an burst.Comparator instance by name.
|