Internationalization and localization tools


Locale-Sensitive C/C++ Collation Function

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

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

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

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

Internationalization (I18n) Function Overview

The strcmp function compares two null-terminated strings. 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. If one string is a prefix of the other, the longer string is greater than the shorter string.

wcscmp is the wide character version of strcmp that compares the two wide-character string arguments.

Supported on Windows platforms only, _mbscmp is the multibyte version of strcmp that compares two multibyte-character strings, using the current multibyte code page.

_tcscmp is the Windows-only Generic version of the function; with the _MBCS or _UNICODE compiler flags determining its mapping to either _mbscmp or wcscmp.

I18n Issues

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

These functions should not be used for character collation, i.e. alphabetization, because outside of the ASCII subset of characters, they will not sort according to the character set sort order rules of a specific locale. Instead, call one of the collation functions listed below.

On ANSI UTF-8 platforms, strcmp will work correctly for an equality comparison. However, on Windows platforms, use _mbscmp or wcscmp for multibyte or wide-character string comparisons.

For Windows MBCS support, ensure that the multibyte code page is set correctly. See _setmbcp for information on setting up the multibyte code page.

Recommended Replacements*

For equality comparisons use

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

For purposes of character collation, there are multibyte and wide functions for handling international sorting. These functions differ from the traditional strcmp in that they use locale-specific sorting rather than collating by a character's encoded value. The value assigned to LC_COLLATE within the machine's environment when the program runs dictates the locale-specific sorting rules drawn from by the collation functions.

For collation use

Collation Functions

 

Lingoport internationalization and localization services and software