开发者

strnicmp equivalent for UTF-8?

开发者 https://www.devze.com 2023-01-01 15:52 出处:网络
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

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消