strncasecmp
⚠️ Deprecated ⚠️
This is deprecated since version 2.2.
The problem with g_strncasecmp()
is that it does the comparison by calling toupper()
/tolower()
. These functions are locale-specific and operate on single bytes. However, it is impossible to handle things correctly from an internationalization standpoint by operating on bytes, since characters may be multibyte. Thus g_strncasecmp()
is broken if your string is guaranteed to be ASCII, since it is locale-sensitive, and it's broken if your string is localized, since it doesn't work on many encodings at all, including UTF-8, EUC-JP, etc.
There are therefore two replacement techniques: func@GLib.ascii_strncasecmp, which only works on ASCII and is not locale-sensitive, and func@GLib.utf8_casefold followed by strcmp()
on the resulting strings, which is good for case-insensitive sorting of UTF-8.
A case-insensitive string comparison, corresponding to the standard strncasecmp()
function on platforms which support it. It is similar to func@GLib.strcasecmp except it only compares the first @n characters of the strings.
Return
0 if the strings match, a negative value if @s1 < @s2, or a positive value if @s1 @s2
Parameters
string to compare with @s2
string to compare with @s1
the maximum number of characters to compare