in src/common/utils/Utf8.h [513:583]
utf8_constexpr14_impl int utf8ncasecmp(const utf8_int8_t *src1, const utf8_int8_t *src2, size_t n) {
utf8_int32_t src1_lwr_cp = 0, src2_lwr_cp = 0, src1_upr_cp = 0, src2_upr_cp = 0, src1_orig_cp = 0, src2_orig_cp = 0;
do {
const utf8_int8_t *const s1 = src1;
const utf8_int8_t *const s2 = src2;
/* first check that we have enough bytes left in n to contain an entire
* codepoint */
if (0 == n) {
return 0;
}
if ((1 == n) && ((0xc0 == (0xe0 & *s1)) || (0xc0 == (0xe0 & *s2)))) {
const utf8_int32_t c1 = (0xe0 & *s1);
const utf8_int32_t c2 = (0xe0 & *s2);
if (c1 < c2) {
return c1 - c2;
} else {
return 0;
}
}
if ((2 >= n) && ((0xe0 == (0xf0 & *s1)) || (0xe0 == (0xf0 & *s2)))) {
const utf8_int32_t c1 = (0xf0 & *s1);
const utf8_int32_t c2 = (0xf0 & *s2);
if (c1 < c2) {
return c1 - c2;
} else {
return 0;
}
}
if ((3 >= n) && ((0xf0 == (0xf8 & *s1)) || (0xf0 == (0xf8 & *s2)))) {
const utf8_int32_t c1 = (0xf8 & *s1);
const utf8_int32_t c2 = (0xf8 & *s2);
if (c1 < c2) {
return c1 - c2;
} else {
return 0;
}
}
src1 = utf8codepoint(src1, &src1_orig_cp);
src2 = utf8codepoint(src2, &src2_orig_cp);
n -= utf8codepointsize(src1_orig_cp);
src1_lwr_cp = utf8lwrcodepoint(src1_orig_cp);
src2_lwr_cp = utf8lwrcodepoint(src2_orig_cp);
src1_upr_cp = utf8uprcodepoint(src1_orig_cp);
src2_upr_cp = utf8uprcodepoint(src2_orig_cp);
/* check if the lowered codepoints match */
if ((0 == src1_orig_cp) && (0 == src2_orig_cp)) {
return 0;
} else if ((src1_lwr_cp == src2_lwr_cp) || (src1_upr_cp == src2_upr_cp)) {
continue;
}
/* if they don't match, then we return the difference between the characters
*/
return src1_lwr_cp - src2_lwr_cp;
} while (0 < n);
/* both utf8 strings matched */
return 0;
}