MakeCompareFunction (open)

Get a function to compare strings

Syntax

LOADLIB "wh::util/localization.whlib";

FUNCTION PTR FUNCTION MakeCompareFunction(STRING locale, STRING sensitivity, BOOLEAN ignorepunctuation, BOOLEAN numeric, STRING casefirst)

Parameters

STRING locale

The language or locale to use (e.g. 'en', 'en-GB', 'nl' or 'zh-Hans-CN')

STRING sensitivity

The comparison sensitivity, one of "base" (a ≠ b, a = á, a = A), "accent" (a ≠ b, a ≠ á, a = A), "case" (a ≠ b, a = á, a ≠ A) or "variant" (a ≠ b, a ≠ á, a ≠ A), if empty, "variant" is assumed

BOOLEAN ignorepunctuation

If punctuation should be ignored (if set to TRUE, ".a" = "a.")

BOOLEAN numeric

If numeric collation should be used (if set to TRUE, "1" < "2" < "10")

STRING casefirst

If upper case or lower case should be sorted first, one of "upper" (sort upper case first), "lower" (sort lower case first) or "false" (use locale default, the default value)

Return value

FUNCTION PTR

A function that can be used to compare two strings, INTEGER FUNCTION(STRING, STRING)

Description

This function creates and returns a compare function based on the given parameters. The returned function can be used to compare two strings and return 0 if the strings are considered equal, -1 if the first string should be sorted before the second string and 1 if the first string should be sorted after the second string.

Examples

// Returns -1
GetCompareFunction("en", "base", FALSE, FALSE)("a", "b");

// Returns 0
GetCompareFunction("en", "base", FALSE, FALSE)("a", "ä");

// Returns 1
GetCompareFunction("en", "base", FALSE, FALSE)("z", "ä");

// Returns -1 (in Swedish, ä is sorted after z
GetCompareFunction("sv", "base", FALSE, FALSE)("z", "ä");