Internationalization and localization tools


Locale-Sensitive C/C++ Collation Function

int _stricoll(const char* string1, const char* string2);

int _wcsicoll(const unsigned wchar_t* string1, const unsigned wchar_t* string2);

int _mbsicoll(const unsigned char* string1, const unsigned char* string2);

int _tcsicoll(const _TXCHAR* string1, const _TXCHAR* string2);

Internationalization (I18n) Function Overview

The _stricoll function performs a case-insensitive compare of two null-terminated strings, interpreting the strings according to the LC_CTYPE and LC_COLLATE categories of the current locale. It returns zero if the strings are equal, a negative number if string1 is less than string2 and a positive number if string1 is greater than string2.

_wcsicoll is the wide character version of _stricoll. It compares the two wide-character string arguments.

_mbsicoll is the multibyte version of _stricoll. It compares two multibyte-character strings, using the current multibyte code page.

_tcsicoll is the Windows-only Generic version of the function; with the _MBCS or _UNICODE compiler flags determining its mapping to either _mbsicoll or _wcsicoll.

I18n Issues

Use the appropriate version of the function as required for internationalization support, noting the following:

The single-byte version of the function, _stricoll, should not be used for collation because it will only work with single-byte characters. Instead, the appropriate multibyte, wide or generic version should be called.

The locale for which this function draws its collation rules can be set via setlocale.

In the case of multibyte characters, ensure that the multibyte code page is set correctly before calling the multibyte or generic version of this function. See _setmbcp for more information on setting up the multibyte code page.

Recommended Replacements*

*If you're already using the recommended function, see I18n Issues for other reasons why Globalyzer is detecting the function.

Performance Issues

Although use of a stricoll function is the simplest way to internationalize existing collation-based stricmp calls, there is a disadvantage.
The *coll() functions are typically slower than the *cmp() functions because they often rely on tables of collation information.

If you can't or don't want to pay the performance price, consider using a strxfrm function instead. This function transforms data and returns strings of characters that can then be passed into a strcmp function to be sorted. In effect, it assigns numeric values to characters using the current locale's sorting rules so that a strcmp function can do numeric comparisons.

Collation Functions

 

Lingoport internationalization and localization services and software