I32
Perl_ibcmp_utf8(pTHX_ const char *s1, bool u1, register I32 len1, const char *s2, bool u2, register I32 len2)
{
- register U8 *a = (U8*)s1;
- register U8 *b = (U8*)s2;
- register U8 *ae = a + len1;
- register U8 *be = b + len2;
- STRLEN la, lb;
- UV ca, cb;
+ register U8 *p1 = (U8*)s1;
+ register U8 *p2 = (U8*)s2;
+ register U8 *e1 = p1 + len1;
+ register U8 *e2 = p2 + len2;
+ STRLEN l1, l2;
+ UV c1, c2;
STRLEN foldlen1, foldlen2;
U8 foldbuf1[UTF8_MAXLEN_FOLD+1];
U8 foldbuf2[UTF8_MAXLEN_FOLD+1];
- while (a < ae && b < be) {
+ while (p1 < e1 && p2 < e2) {
if (u1) {
- if (a + UTF8SKIP(a) > ae)
+ if (p1 + UTF8SKIP(p1) > e1)
break;
- ca = utf8_to_uvchr((U8*)a, &la);
+ c1 = utf8_to_uvchr((U8*)p1, &l1);
} else {
- ca = NATIVE_TO_UNI(*a);
- la = 1;
+ c1 = NATIVE_TO_UNI(*p1);
+ l1 = 1;
}
if (u2) {
- if (b + UTF8SKIP(b) > be)
+ if (p2 + UTF8SKIP(p2) > e2)
break;
- cb = utf8_to_uvchr((U8*)b, &lb);
+ c2 = utf8_to_uvchr((U8*)p2, &l2);
} else {
- cb = NATIVE_TO_UNI(*b);
- lb = 1;
+ c2 = NATIVE_TO_UNI(*p2);
+ l2 = 1;
}
- if (ca != cb) {
- to_uni_fold(ca, foldbuf1, &foldlen1);
- ca = utf8_to_uvchr(foldbuf1, 0);
+ if (c1 != c2) {
+ to_uni_fold(c1, foldbuf1, &foldlen1);
+ c1 = utf8_to_uvchr(foldbuf1, 0);
- to_uni_fold(cb, foldbuf2, &foldlen2);
- cb = utf8_to_uvchr(foldbuf2, 0);
+ to_uni_fold(c2, foldbuf2, &foldlen2);
+ c2 = utf8_to_uvchr(foldbuf2, 0);
- if (ca != cb || foldlen1 != foldlen2)
+ if (c1 != c2 || foldlen1 != foldlen2)
return 1; /* mismatch */
}
- a += la;
- b += lb;
+ p1 += l1;
+ p2 += l2;
}
- return a == ae && b == be ? 0 : 1; /* 0 match, 1 mismatch */
+ return p1 == e1 && p2 == e2 ? 0 : 1; /* 0 match, 1 mismatch */
}