From 2c1425898d21fb050da69eb5f423e6f4ba86080a Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 6 May 2020 11:05:08 +0200 Subject: [PATCH] Modernize foldCase() internal functions Overload uint/ushort versions with new char16_t/char32_t ones, and [[deprecate]] the old ones. There's too much churn for doing the replacement in one patch. Change-Id: Ib1f90a1c46b80aa0fb1ea00ce614af49f49bd712 Reviewed-by: Lars Knoll --- src/corelib/text/qchar.cpp | 25 +++++++++++++++++++++++++ src/corelib/text/qstring.cpp | 2 +- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/corelib/text/qchar.cpp b/src/corelib/text/qchar.cpp index 94d2322fa6..49622bf196 100644 --- a/src/corelib/text/qchar.cpp +++ b/src/corelib/text/qchar.cpp @@ -1692,6 +1692,7 @@ char32_t QChar::toTitleCase(char32_t ucs4) noexcept return convertCase_helper(ucs4, QUnicodeTables::TitleCase); } +[[deprecated]] static inline uint foldCase(const ushort *ch, const ushort *start) { char32_t ucs4 = *ch; @@ -1700,6 +1701,15 @@ static inline uint foldCase(const ushort *ch, const ushort *start) return convertCase_helper(ucs4, QUnicodeTables::CaseFold); } +static inline char32_t foldCase(const char16_t *ch, const char16_t *start) +{ + char32_t ucs4 = *ch; + if (QChar::isLowSurrogate(ucs4) && ch > start && QChar::isHighSurrogate(*(ch - 1))) + ucs4 = QChar::surrogateToUcs4(*(ch - 1), ucs4); + return convertCase_helper(ucs4, QUnicodeTables::CaseFold); +} + +[[deprecated]] static inline uint foldCase(uint ch, uint &last) noexcept { char32_t ucs4 = ch; @@ -1709,11 +1719,26 @@ static inline uint foldCase(uint ch, uint &last) noexcept return convertCase_helper(ucs4, QUnicodeTables::CaseFold); } +static inline char32_t foldCase(char32_t ch, char32_t &last) noexcept +{ + char32_t ucs4 = ch; + if (QChar::isLowSurrogate(ucs4) && QChar::isHighSurrogate(last)) + ucs4 = QChar::surrogateToUcs4(last, ucs4); + last = ch; + return convertCase_helper(ucs4, QUnicodeTables::CaseFold); +} + +[[deprecated]] static inline ushort foldCase(ushort ch) noexcept { return convertCase_helper(char16_t{ch}, QUnicodeTables::CaseFold); } +static inline char16_t foldCase(char16_t ch) noexcept +{ + return convertCase_helper(ch, QUnicodeTables::CaseFold); +} + static inline QChar foldCase(QChar ch) noexcept { return QChar(foldCase(ch.unicode())); diff --git a/src/corelib/text/qstring.cpp b/src/corelib/text/qstring.cpp index bd8f536587..6b825212d3 100644 --- a/src/corelib/text/qstring.cpp +++ b/src/corelib/text/qstring.cpp @@ -879,7 +879,7 @@ static int ucstricmp(const QChar *a, const QChar *ae, const char *b, const char e = a + (be - b); while (a < e) { - int diff = foldCase(a->unicode()) - foldCase(uchar(*b)); + int diff = foldCase(a->unicode()) - foldCase(char16_t{uchar(*b)}); if ((diff)) return diff; ++a;