QString: merge the two ucstrcmp overloads into a template
So we don't accidentally make modifications to one and not the other. Change-Id: I0e5f6bec596a4a78bd3bfffd16c94f1025aea521 Reviewed-by: Marc Mutz <marc.mutz@qt.io>
This commit is contained in:
parent
2932c3f942
commit
3d70b291ed
@ -1198,8 +1198,9 @@ static int ucstrncmp(const QChar *a, const QChar *b, size_t l)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int ucstrncmp(const QChar *a, const uchar *c, size_t l)
|
||||
static int ucstrncmp(const QChar *a, const char *b, size_t l)
|
||||
{
|
||||
const uchar *c = reinterpret_cast<const uchar *>(b);
|
||||
const char16_t *uc = reinterpret_cast<const char16_t *>(a);
|
||||
const char16_t *e = uc + l;
|
||||
|
||||
@ -1328,22 +1329,18 @@ static bool ucstreq(const QChar *a, size_t alen, const Char2 *b, size_t blen)
|
||||
}
|
||||
|
||||
// Unicode case-sensitive comparison
|
||||
static int ucstrcmp(const QChar *a, size_t alen, const QChar *b, size_t blen)
|
||||
template <typename Char2>
|
||||
static int ucstrcmp(const QChar *a, size_t alen, const Char2 *b, size_t blen)
|
||||
{
|
||||
if (a == b && alen == blen)
|
||||
return 0;
|
||||
if constexpr (std::is_same_v<decltype(a), decltype(b)>) {
|
||||
if (a == b && alen == blen)
|
||||
return 0;
|
||||
}
|
||||
const size_t l = qMin(alen, blen);
|
||||
int cmp = ucstrncmp(a, b, l);
|
||||
return cmp ? cmp : lencmp(alen, blen);
|
||||
}
|
||||
|
||||
static int ucstrcmp(const QChar *a, size_t alen, const char *b, size_t blen)
|
||||
{
|
||||
const size_t l = qMin(alen, blen);
|
||||
const int cmp = ucstrncmp(a, reinterpret_cast<const uchar*>(b), l);
|
||||
return cmp ? cmp : lencmp(alen, blen);
|
||||
}
|
||||
|
||||
static constexpr uchar latin1Lower[256] = {
|
||||
0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,
|
||||
0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f,
|
||||
|
Loading…
Reference in New Issue
Block a user