Internationalization and localization tools


Locale-Sensitive C/C++ Collation Function

int strncasecmp(const char *s1, const char *s2, size_t n);

int wcsncasecmp(const wchar_t *ws1, const wchar_t *s2, size_t n);

Internationalization (I18n) Function Overview

strncasecmp is like strncmp, except that differences in case are ignored. Like strcasecmp, it is locale dependent with regards to how uppercase and lowercase characters are related.

wcsncasecmp is like wcsncmp, except that differences in case are ignored. Like wcscasecmp, it is locale dependent with regards to how uppercase and lowercase characters are related.

I18n Issues

The single-byte version of the function, strncasecmp, should not be used for equality comparison, because it will only work with single-byte characters. On ANSI UTF-8 platforms, convert the UTF-8 strings to wide character strings and then call wcsncasecmp on the wide strings.

In addition, 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.

Prior to calling one of these functions, ensure that the current locale is set properly by calling setlocale, as string comparison is dependent on the LC_CTYPE locale category.

Ensure that the n argument value is correct for the function call; the number of bytes for strncasecmp, and the number of wide characters for wcsncasecmp. See Locale-Sensitive Length Functions for a discussion on multibyte and wide character sizes.

Recommended Replacements*

For equality comparisons use

For purposes of character collation, there are multibyte and wide functions for handling international sorting. These functions differ from the traditional strncasecmp 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

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

Collation Functions

 

Lingoport internationalization and localization services and software