bool equalIgnoringCase(StringImpl* a, const char* b) { if (!a) return !b; if (!b) return !a; unsigned length = a->length(); const UChar* as = a->characters(); // Do a faster loop for the case where all the characters are ASCII. UChar ored = 0; bool equal = true; for (unsigned i = 0; i != length; ++i) { char bc = b[i]; if (!bc) return false; UChar ac = as[i]; ored |= ac; equal = equal && (toASCIILower(ac) == toASCIILower(bc)); } // Do a slower implementation for cases that include non-ASCII characters. if (ored & ~0x7F) { equal = true; for (unsigned i = 0; i != length; ++i) { unsigned char bc = b[i]; equal = equal && (foldCase(as[i]) == foldCase(bc)); } } return equal && !b[length]; }
static inline int bm_find(const ushort *uc, uint l, int index, const ushort *puc, uint pl, const uchar *skiptable, Qt::CaseSensitivity cs) { if (pl == 0) return index > (int)l ? -1 : index; const uint pl_minus_one = pl - 1; const ushort *current = uc + index + pl_minus_one; const ushort *end = uc + l; if (cs == Qt::CaseSensitive) { while (current < end) { uint skip = skiptable[*current & 0xff]; if (!skip) { // possible match while (skip < pl) { if (*(current - skip) != puc[pl_minus_one-skip]) break; skip++; } if (skip > pl_minus_one) // we have a match return (current - uc) - pl_minus_one; // in case we don't have a match we are a bit inefficient as we only skip by one // when we have the non matching char in the string. if (skiptable[*(current - skip) & 0xff] == pl) skip = pl - skip; else skip = 1; } if (current > end - skip) break; current += skip; } } else { while (current < end) { uint skip = skiptable[foldCase(current, uc) & 0xff]; if (!skip) { // possible match while (skip < pl) { if (foldCase(current - skip, uc) != foldCase(puc + pl_minus_one - skip, puc)) break; skip++; } if (skip > pl_minus_one) // we have a match return (current - uc) - pl_minus_one; // in case we don't have a match we are a bit inefficient as we only skip by one // when we have the non matching char in the string. if (skiptable[foldCase(current - skip, uc) & 0xff] == pl) skip = pl - skip; else skip = 1; } if (current > end - skip) break; current += skip; } } return -1; // not found }
bool equalIgnoringCase(const UChar* a, const char* b, unsigned length) { while (length--) { unsigned char bc = *b++; if (foldCase(*a++) != foldCase(bc)) return false; } return true; }
static bool equalIgnoringCase(const UChar* a, const char* b, int length) { ASSERT(length >= 0); while (length--) { unsigned char bc = *b++; if (foldCase(*a++) != foldCase(bc)) return false; } return true; }
int foldCase(wchar_t* result, int resultLength, const wchar_t* source, int sourceLength, bool* isError) { *isError = false; if (resultLength < sourceLength) { *isError = true; return sourceLength; } for (int i = 0; i < sourceLength; ++i) result[i] = foldCase(source[i]); return sourceLength; }
int foldCase(UChar* result, int resultLength, const UChar* src, int srcLength, bool* error) { *error = false; if (resultLength < srcLength) { *error = true; return srcLength; } for (int i = 0; i < srcLength; ++i) result[i] = foldCase(src[i]); return srcLength; }
QT_BEGIN_NAMESPACE static void bm_init_skiptable(const ushort *uc, int len, uchar *skiptable, Qt::CaseSensitivity cs) { int l = qMin(len, 255); memset(skiptable, l, 256*sizeof(uchar)); uc += len - l; if (cs == Qt::CaseSensitive) { while (l--) { skiptable[*uc & 0xff] = l; uc++; } } else { const ushort *start = uc; while (l--) { skiptable[foldCase(uc, start) & 0xff] = l; uc++; } } }
QT_BEGIN_NAMESPACE static void bm_init_skiptable(const ushort *uc, int l, uint *skiptable, Qt::CaseSensitivity cs) { int i = 0; register uint *st = skiptable; while (i++ < 256 / 8) { *st++ = l; *st++ = l; *st++ = l; *st++ = l; *st++ = l; *st++ = l; *st++ = l; *st++ = l; } if (cs == Qt::CaseSensitive) { while (l--) { skiptable[*uc & 0xff] = l; uc++; } } else { const ushort *start = uc; while (l--) { skiptable[foldCase(uc, start) & 0xff] = l; uc++; } } }