From 3d70b291eda8d340616b562f9e7d5bff57e05d22 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Tue, 11 Jan 2022 11:47:49 -0800 Subject: 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 --- src/corelib/text/qstring.cpp | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/src/corelib/text/qstring.cpp b/src/corelib/text/qstring.cpp index 594b0d2298..14d3e214a1 100644 --- a/src/corelib/text/qstring.cpp +++ b/src/corelib/text/qstring.cpp @@ -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(b); const char16_t *uc = reinterpret_cast(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 +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) { + 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(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, -- cgit v1.2.3