Locale-Sensitive C/C++ Collation Function
int strverscmp(const char *s1, const char *s2);
Internationalization (I18n) Function Overview
The strverscmp function compares the string s1 against s2 , considering them as holding indices/version numbers. Return value follows the same conventions as found in the strcmp function. In fact, if s1 and s2 contain no digits, strverscmp behaves like strcmp .
The algorithm that is used compares strings normally (character by character), until a digit is
found in each string. Then, special comparison rules are followed to compare those sequence of digits.
If there is no difference between the digits, then the comparison returns to the normal comparison mode.
This function is especially useful when dealing with filename sorting, because filenames frequently hold indices/version numbers.
I18n Issues
strverscmp is a special comparison function that should only be used when
there is no desire for character collation of UTF-8 non-ASCII characters. This is because
outside of the ASCII subset of characters, the strings will not sort according to the character
set sort order rules of a specific locale.
There is also no wide version of strverscmp . On ANSI wide character platforms,
use a conversion function to convert the wide-character strings to
multibyte-character strings and call strverscmp .
Prior to calling this function, ensure that the current locale is set properly by calling setlocale, as string comparison is dependent on the LC_CTYPE locale category.
Recommended Replacements*
*If you're already using the recommended function, see I18n Issues for other reasons why Globalyzer is detecting the function.
Collation Functions
|