NaviServer - programmable web server
4.99  5.0

[ Main Table Of Contents | Table Of Contents | Keyword Index ]

ns_strcoll(n) 4.99.30 naviserver "NaviServer Built-in Commands"

Name

ns_strcoll - Compare strings according to the current locale collation

Table Of Contents

Synopsis

Description

COMMANDS

ns_strcoll ?-locale locale? string1 string2

This command compares lexicographically string1 with string2 according to the current locale collation and returns an integer greater than, equal to, or less than 0, depending on whether string1 is greater than, equal to, or less than string2. The command is necessary in cases, where e.g. the sorting order from the database (normally based on local collation) is different from default Tcl sorting order to provide a uniform interface with same sorting orders. The name of the function is derived from the baseline POSIX function call.

When the option -locale is not set, the LC_COLLATE value is determined by the operating system (looking into the settings of LC_ALL, LC_COLLATE and LANG). When locale is specified, it is recommended to use the specification consisting of language, territory and charset (e.g. en_US.UTF-8.

Note that the output of the command depends on correct installation of locales on the host. Furthermore, the output of the command varies depending on the C library's implementation. Some implementations support further advanced sorting features such as case-folding collation, ignoring preceding dashes etc. especially for UTF-8 locales, other implementations don't. Future versions of the function might consider using the ICU library (International Components for Unicode) for further cross-platform compatibility.

EXAMPLES

The command is suitable for usage in the Tcl lsort command:

 % set l {Bor Bar Bär}
 % lsort -command ns_strcoll $l
 Bar Bär Bor
 
 % lsort $l
 Bar Bor Bär 
 % lsort -command {ns_strcoll -locale en_US.UTF-8} $l
 Bar Bär Bor

Keywords

LC_COLLATE, compare, global built-in, i18n, locale