From 7b04e0012b40203970f27869db2ab3e838ffe359 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Thu, 23 Apr 2020 21:10:48 +0200 Subject: QUnicodeTables: port to charNN_t This makes existing calls passing uint or ushort ambiguous, so fix all the callers. There do not appear to be callers outside QtBase. In fact, the ...BreakClass() functions appear to be utterly unused. Change-Id: I1c2251920beba48d4909650bc1d501375c6a3ecf Reviewed-by: Lars Knoll Reviewed-by: Konstantin Ritt --- src/corelib/text/qchar.cpp | 26 ++++++++++++------------- src/corelib/text/qunicodetables.cpp | 26 ++++++++----------------- src/corelib/text/qunicodetables_p.h | 12 ++++++------ src/corelib/text/qunicodetools.cpp | 10 +++++----- src/gui/text/qtextengine.cpp | 4 ++-- util/unicode/main.cpp | 38 ++++++++++++++----------------------- 6 files changed, 48 insertions(+), 68 deletions(-) diff --git a/src/corelib/text/qchar.cpp b/src/corelib/text/qchar.cpp index eb9ac13a07..538c282c6f 100644 --- a/src/corelib/text/qchar.cpp +++ b/src/corelib/text/qchar.cpp @@ -1633,7 +1633,7 @@ char32_t QChar::toTitleCase(char32_t ucs4) noexcept static inline uint foldCase(const ushort *ch, const ushort *start) { - uint ucs4 = *ch; + 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); @@ -1641,7 +1641,7 @@ static inline uint foldCase(const ushort *ch, const ushort *start) static inline uint foldCase(uint ch, uint &last) noexcept { - uint ucs4 = ch; + char32_t ucs4 = ch; if (QChar::isLowSurrogate(ucs4) && QChar::isHighSurrogate(last)) ucs4 = QChar::surrogateToUcs4(last, ucs4); last = ch; @@ -1650,7 +1650,7 @@ static inline uint foldCase(uint ch, uint &last) noexcept static inline ushort foldCase(ushort ch) noexcept { - return convertCase_helper(ch, QUnicodeTables::CaseFold); + return convertCase_helper(char16_t{ch}, QUnicodeTables::CaseFold); } static inline QChar foldCase(QChar ch) noexcept @@ -1953,7 +1953,7 @@ static void composeHelper(QString *str, QChar::UnicodeVersion version, int from) int pos = from; while (pos < s.length()) { int i = pos; - uint uc = s.at(pos).unicode(); + char32_t uc = s.at(pos).unicode(); if (QChar(uc).isHighSurrogate() && pos < s.length()-1) { ushort low = s.at(pos+1).unicode(); if (QChar(low).isLowSurrogate()) { @@ -2007,16 +2007,16 @@ static void canonicalOrderHelper(QString *str, QChar::UnicodeVersion version, in QString &s = *str; const int l = s.length()-1; - uint u1, u2; - ushort c1, c2; + char32_t u1, u2; + char16_t c1, c2; int pos = from; while (pos < l) { int p2 = pos+1; u1 = s.at(pos).unicode(); - if (QChar(u1).isHighSurrogate()) { - ushort low = s.at(p2).unicode(); - if (QChar(low).isLowSurrogate()) { + if (QChar::isHighSurrogate(u1)) { + const char16_t low = s.at(p2).unicode(); + if (QChar::isLowSurrogate(low)) { u1 = QChar::surrogateToUcs4(u1, low); if (p2 >= l) break; @@ -2027,9 +2027,9 @@ static void canonicalOrderHelper(QString *str, QChar::UnicodeVersion version, in advance: u2 = s.at(p2).unicode(); - if (QChar(u2).isHighSurrogate() && p2 < l) { - ushort low = s.at(p2+1).unicode(); - if (QChar(low).isLowSurrogate()) { + if (QChar::isHighSurrogate(u2) && p2 < l) { + const char16_t low = s.at(p2+1).unicode(); + if (QChar::isLowSurrogate(low)) { u2 = QChar::surrogateToUcs4(u2, low); ++p2; } @@ -2111,7 +2111,7 @@ static bool normalizationQuickCheckHelper(QString *str, QString::NormalizationFo uchar lastCombining = 0; for (int i = from; i < length; ++i) { int pos = i; - uint uc = string[i]; + char32_t uc = string[i]; if (uc < 0x80) { // ASCII characters are stable code points lastCombining = 0; diff --git a/src/corelib/text/qunicodetables.cpp b/src/corelib/text/qunicodetables.cpp index a0d210b13d..e6f6487126 100644 --- a/src/corelib/text/qunicodetables.cpp +++ b/src/corelib/text/qunicodetables.cpp @@ -9598,52 +9598,42 @@ static const Properties uc_properties[] = { { 12, 0, 0, 0, -1, 0, 2, 0, { {0, 0}, {0, 0}, {0, 0}, {0, 0} }, 0, 0, 12, 0, 0 } }; -Q_DECL_CONST_FUNCTION static inline const Properties *qGetProp(uint ucs4) noexcept -{ - return uc_properties + GET_PROP_INDEX(ucs4); -} - Q_DECL_CONST_FUNCTION static inline const Properties *qGetProp(char32_t ucs4) noexcept { - return qGetProp(uint{ucs4}); -} - -Q_DECL_CONST_FUNCTION static inline const Properties *qGetProp(ushort ucs2) noexcept -{ - return uc_properties + GET_PROP_INDEX_UCS2(ucs2); + return uc_properties + GET_PROP_INDEX(ucs4); } Q_DECL_CONST_FUNCTION static inline const Properties *qGetProp(char16_t ucs2) noexcept { - return qGetProp(ushort{ucs2}); + return uc_properties + GET_PROP_INDEX_UCS2(ucs2); } -Q_DECL_CONST_FUNCTION Q_CORE_EXPORT const Properties * QT_FASTCALL properties(uint ucs4) noexcept +Q_DECL_CONST_FUNCTION Q_CORE_EXPORT const Properties * QT_FASTCALL properties(char32_t ucs4) noexcept { return qGetProp(ucs4); } -Q_DECL_CONST_FUNCTION Q_CORE_EXPORT const Properties * QT_FASTCALL properties(ushort ucs2) noexcept +Q_DECL_CONST_FUNCTION Q_CORE_EXPORT const Properties * QT_FASTCALL properties(char16_t ucs2) noexcept { return qGetProp(ucs2); } -Q_CORE_EXPORT GraphemeBreakClass QT_FASTCALL graphemeBreakClass(uint ucs4) noexcept +Q_CORE_EXPORT GraphemeBreakClass QT_FASTCALL graphemeBreakClass(char32_t ucs4) noexcept { return static_cast(qGetProp(ucs4)->graphemeBreakClass); } -Q_CORE_EXPORT WordBreakClass QT_FASTCALL wordBreakClass(uint ucs4) noexcept +Q_CORE_EXPORT WordBreakClass QT_FASTCALL wordBreakClass(char32_t ucs4) noexcept { return static_cast(qGetProp(ucs4)->wordBreakClass); } -Q_CORE_EXPORT SentenceBreakClass QT_FASTCALL sentenceBreakClass(uint ucs4) noexcept +Q_CORE_EXPORT SentenceBreakClass QT_FASTCALL sentenceBreakClass(char32_t ucs4) noexcept { return static_cast(qGetProp(ucs4)->sentenceBreakClass); } -Q_CORE_EXPORT LineBreakClass QT_FASTCALL lineBreakClass(uint ucs4) noexcept +Q_CORE_EXPORT LineBreakClass QT_FASTCALL lineBreakClass(char32_t ucs4) noexcept { return static_cast(qGetProp(ucs4)->lineBreakClass); } diff --git a/src/corelib/text/qunicodetables_p.h b/src/corelib/text/qunicodetables_p.h index 3578bb885f..c8815e7919 100644 --- a/src/corelib/text/qunicodetables_p.h +++ b/src/corelib/text/qunicodetables_p.h @@ -98,8 +98,8 @@ struct Properties { ushort script : 8; }; -Q_CORE_EXPORT const Properties * QT_FASTCALL properties(uint ucs4) noexcept; -Q_CORE_EXPORT const Properties * QT_FASTCALL properties(ushort ucs2) noexcept; +Q_CORE_EXPORT const Properties * QT_FASTCALL properties(char32_t ucs4) noexcept; +Q_CORE_EXPORT const Properties * QT_FASTCALL properties(char16_t ucs2) noexcept; Q_STATIC_ASSERT(sizeof(Properties) == 20); @@ -189,19 +189,19 @@ enum LineBreakClass { NumLineBreakClasses }; -Q_CORE_EXPORT GraphemeBreakClass QT_FASTCALL graphemeBreakClass(uint ucs4) noexcept; +Q_CORE_EXPORT GraphemeBreakClass QT_FASTCALL graphemeBreakClass(char32_t ucs4) noexcept; inline GraphemeBreakClass graphemeBreakClass(QChar ch) noexcept { return graphemeBreakClass(ch.unicode()); } -Q_CORE_EXPORT WordBreakClass QT_FASTCALL wordBreakClass(uint ucs4) noexcept; +Q_CORE_EXPORT WordBreakClass QT_FASTCALL wordBreakClass(char32_t ucs4) noexcept; inline WordBreakClass wordBreakClass(QChar ch) noexcept { return wordBreakClass(ch.unicode()); } -Q_CORE_EXPORT SentenceBreakClass QT_FASTCALL sentenceBreakClass(uint ucs4) noexcept; +Q_CORE_EXPORT SentenceBreakClass QT_FASTCALL sentenceBreakClass(char32_t ucs4) noexcept; inline SentenceBreakClass sentenceBreakClass(QChar ch) noexcept { return sentenceBreakClass(ch.unicode()); } -Q_CORE_EXPORT LineBreakClass QT_FASTCALL lineBreakClass(uint ucs4) noexcept; +Q_CORE_EXPORT LineBreakClass QT_FASTCALL lineBreakClass(char32_t ucs4) noexcept; inline LineBreakClass lineBreakClass(QChar ch) noexcept { return lineBreakClass(ch.unicode()); } diff --git a/src/corelib/text/qunicodetools.cpp b/src/corelib/text/qunicodetools.cpp index 819d8a9c3b..61976ab9ca 100644 --- a/src/corelib/text/qunicodetools.cpp +++ b/src/corelib/text/qunicodetools.cpp @@ -103,7 +103,7 @@ static void getGraphemeBreaks(const ushort *string, quint32 len, QCharAttributes GB::State state = GB::Break; // only required to track some of the rules for (quint32 i = 0; i != len; ++i) { quint32 pos = i; - uint ucs4 = string[i]; + char32_t ucs4 = string[i]; if (QChar::isHighSurrogate(ucs4) && i + 1 != len) { ushort low = string[i + 1]; if (QChar::isLowSurrogate(low)) { @@ -200,7 +200,7 @@ static void getWordBreaks(const ushort *string, quint32 len, QCharAttributes *at QUnicodeTables::WordBreakClass cls = QUnicodeTables::WordBreak_LF; // to meet WB1 for (quint32 i = 0; i != len; ++i) { quint32 pos = i; - uint ucs4 = string[i]; + char32_t ucs4 = string[i]; if (QChar::isHighSurrogate(ucs4) && i + 1 != len) { ushort low = string[i + 1]; if (QChar::isLowSurrogate(low)) { @@ -348,7 +348,7 @@ static void getSentenceBreaks(const ushort *string, quint32 len, QCharAttributes uchar state = SB::BAfter; // to meet SB1 for (quint32 i = 0; i != len; ++i) { quint32 pos = i; - uint ucs4 = string[i]; + char32_t ucs4 = string[i]; if (QChar::isHighSurrogate(ucs4) && i + 1 != len) { ushort low = string[i + 1]; if (QChar::isLowSurrogate(low)) { @@ -551,7 +551,7 @@ static void getLineBreaks(const ushort *string, quint32 len, QCharAttributes *at QUnicodeTables::LineBreakClass cls = lcls; for (quint32 i = 0; i != len; ++i) { quint32 pos = i; - uint ucs4 = string[i]; + char32_t ucs4 = string[i]; if (QChar::isHighSurrogate(ucs4) && i + 1 != len) { ushort low = string[i + 1]; if (QChar::isLowSurrogate(low)) { @@ -2254,7 +2254,7 @@ Q_CORE_EXPORT void initScripts(const ushort *string, int length, ScriptItemArray QChar::Script script = QChar::Script_Common; for (int i = 0; i < length; ++i, eor = i) { - uint ucs4 = string[i]; + char32_t ucs4 = string[i]; if (QChar::isHighSurrogate(ucs4) && i + 1 < length) { ushort low = string[i + 1]; if (QChar::isLowSurrogate(low)) { diff --git a/src/gui/text/qtextengine.cpp b/src/gui/text/qtextengine.cpp index 990dfa2537..4a3ce02a18 100644 --- a/src/gui/text/qtextengine.cpp +++ b/src/gui/text/qtextengine.cpp @@ -257,7 +257,7 @@ struct QBidiAlgorithm { // load directions of string, and determine isolate pairs for (int i = 0; i < length; ++i) { int pos = i; - uint uc = text[i].unicode(); + char32_t uc = text[i].unicode(); if (QChar::isHighSurrogate(uc) && i < length - 1) { ++i; analysis[i].bidiDirection = QChar::DirNSM; @@ -829,7 +829,7 @@ struct QBidiAlgorithm { int pos = *it; QChar::Direction dir = analysis[pos].bidiDirection; if (dir == QChar::DirON) { - const QUnicodeTables::Properties *p = QUnicodeTables::properties(text[pos].unicode()); + const QUnicodeTables::Properties *p = QUnicodeTables::properties(char16_t{text[pos].unicode()}); if (p->mirrorDiff) { // either opening or closing bracket if (p->category == QChar::Punctuation_Open) { diff --git a/util/unicode/main.cpp b/util/unicode/main.cpp index 6434d784fe..e89d4e4706 100644 --- a/util/unicode/main.cpp +++ b/util/unicode/main.cpp @@ -851,24 +851,24 @@ static const char *property_string = " ushort sentenceBreakClass : 8; /* 4 used */\n" " ushort script : 8;\n" "};\n\n" - "Q_CORE_EXPORT const Properties * QT_FASTCALL properties(uint ucs4) noexcept;\n" - "Q_CORE_EXPORT const Properties * QT_FASTCALL properties(ushort ucs2) noexcept;\n" + "Q_CORE_EXPORT const Properties * QT_FASTCALL properties(char32_t ucs4) noexcept;\n" + "Q_CORE_EXPORT const Properties * QT_FASTCALL properties(char16_t ucs2) noexcept;\n" "\n"; static const char *methods = - "Q_CORE_EXPORT GraphemeBreakClass QT_FASTCALL graphemeBreakClass(uint ucs4) noexcept;\n" + "Q_CORE_EXPORT GraphemeBreakClass QT_FASTCALL graphemeBreakClass(char32_t ucs4) noexcept;\n" "inline GraphemeBreakClass graphemeBreakClass(QChar ch) noexcept\n" "{ return graphemeBreakClass(ch.unicode()); }\n" "\n" - "Q_CORE_EXPORT WordBreakClass QT_FASTCALL wordBreakClass(uint ucs4) noexcept;\n" + "Q_CORE_EXPORT WordBreakClass QT_FASTCALL wordBreakClass(char32_t ucs4) noexcept;\n" "inline WordBreakClass wordBreakClass(QChar ch) noexcept\n" "{ return wordBreakClass(ch.unicode()); }\n" "\n" - "Q_CORE_EXPORT SentenceBreakClass QT_FASTCALL sentenceBreakClass(uint ucs4) noexcept;\n" + "Q_CORE_EXPORT SentenceBreakClass QT_FASTCALL sentenceBreakClass(char32_t ucs4) noexcept;\n" "inline SentenceBreakClass sentenceBreakClass(QChar ch) noexcept\n" "{ return sentenceBreakClass(ch.unicode()); }\n" "\n" - "Q_CORE_EXPORT LineBreakClass QT_FASTCALL lineBreakClass(uint ucs4) noexcept;\n" + "Q_CORE_EXPORT LineBreakClass QT_FASTCALL lineBreakClass(char32_t ucs4) noexcept;\n" "inline LineBreakClass lineBreakClass(QChar ch) noexcept\n" "{ return lineBreakClass(ch.unicode()); }\n" "\n"; @@ -2528,52 +2528,42 @@ static QByteArray createPropertyInfo() out += "\n};\n\n"; - out += "Q_DECL_CONST_FUNCTION static inline const Properties *qGetProp(uint ucs4) noexcept\n" + out += "Q_DECL_CONST_FUNCTION static inline const Properties *qGetProp(char32_t ucs4) noexcept\n" "{\n" " return uc_properties + GET_PROP_INDEX(ucs4);\n" "}\n" "\n" - "Q_DECL_CONST_FUNCTION static inline const Properties *qGetProp(char32_t ucs4) noexcept\n" - "{\n" - " return qGetProp(uint{ucs4});\n" - "}\n" - "\n" - "Q_DECL_CONST_FUNCTION static inline const Properties *qGetProp(ushort ucs2) noexcept\n" - "{\n" - " return uc_properties + GET_PROP_INDEX_UCS2(ucs2);\n" - "}\n" - "\n" "Q_DECL_CONST_FUNCTION static inline const Properties *qGetProp(char16_t ucs2) noexcept\n" "{\n" - " return qGetProp(ushort{ucs2});\n" + " return uc_properties + GET_PROP_INDEX_UCS2(ucs2);\n" "}\n" "\n" - "Q_DECL_CONST_FUNCTION Q_CORE_EXPORT const Properties * QT_FASTCALL properties(uint ucs4) noexcept\n" + "Q_DECL_CONST_FUNCTION Q_CORE_EXPORT const Properties * QT_FASTCALL properties(char32_t ucs4) noexcept\n" "{\n" " return qGetProp(ucs4);\n" "}\n" "\n" - "Q_DECL_CONST_FUNCTION Q_CORE_EXPORT const Properties * QT_FASTCALL properties(ushort ucs2) noexcept\n" + "Q_DECL_CONST_FUNCTION Q_CORE_EXPORT const Properties * QT_FASTCALL properties(char16_t ucs2) noexcept\n" "{\n" " return qGetProp(ucs2);\n" "}\n\n"; - out += "Q_CORE_EXPORT GraphemeBreakClass QT_FASTCALL graphemeBreakClass(uint ucs4) noexcept\n" + out += "Q_CORE_EXPORT GraphemeBreakClass QT_FASTCALL graphemeBreakClass(char32_t ucs4) noexcept\n" "{\n" " return static_cast(qGetProp(ucs4)->graphemeBreakClass);\n" "}\n" "\n" - "Q_CORE_EXPORT WordBreakClass QT_FASTCALL wordBreakClass(uint ucs4) noexcept\n" + "Q_CORE_EXPORT WordBreakClass QT_FASTCALL wordBreakClass(char32_t ucs4) noexcept\n" "{\n" " return static_cast(qGetProp(ucs4)->wordBreakClass);\n" "}\n" "\n" - "Q_CORE_EXPORT SentenceBreakClass QT_FASTCALL sentenceBreakClass(uint ucs4) noexcept\n" + "Q_CORE_EXPORT SentenceBreakClass QT_FASTCALL sentenceBreakClass(char32_t ucs4) noexcept\n" "{\n" " return static_cast(qGetProp(ucs4)->sentenceBreakClass);\n" "}\n" "\n" - "Q_CORE_EXPORT LineBreakClass QT_FASTCALL lineBreakClass(uint ucs4) noexcept\n" + "Q_CORE_EXPORT LineBreakClass QT_FASTCALL lineBreakClass(char32_t ucs4) noexcept\n" "{\n" " return static_cast(qGetProp(ucs4)->lineBreakClass);\n" "}\n" -- cgit v1.2.3