strnicmp equivalent for UTF-8?
What do I use to perform a case-insensitive comparison on two UTF-8 encoded sub-strings? Essentially, I'm looking for a strnicmp
function for UTF开发者_C百科-8.
Case conversion rules in various Unicode scripts are murderously difficult, it requires large case conversion tables. You cannot get this right yourself, you'll need a library. ICU is one of them.
strcoll
should be locale aware and treat correctly UTF8 at least if it is the default encoding of the locale. If it is not, I have still no idea. Like a workaround, you can convert the multibyte string into wchars (mbrtowc) and then use wcscasecmp which unfortunately is a GNU extension, not a part of standard libraries... Not so useful maybe.
精彩评论