diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2022-01-11 11:47:49 -0800 |
---|---|---|
committer | Thiago Macieira <thiago.macieira@intel.com> | 2022-01-18 21:38:12 -0800 |
commit | 3d70b291eda8d340616b562f9e7d5bff57e05d22 (patch) | |
tree | 6242356634e4a4b9208997082d32e8e4718fb7c3 /src/corelib/text | |
parent | 2932c3f942b4f52f113a52fbeb261a14c4e14cd4 (diff) |
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>
Diffstat (limited to 'src/corelib/text')
-rw-r--r-- | src/corelib/text/qstring.cpp | 19 |
1 files 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<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, |