summaryrefslogtreecommitdiffstats
path: root/src/corelib/text/qchar.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/text/qchar.h')
-rw-r--r--src/corelib/text/qchar.h382
1 files changed, 179 insertions, 203 deletions
diff --git a/src/corelib/text/qchar.h b/src/corelib/text/qchar.h
index 056101325e..c0c53664c2 100644
--- a/src/corelib/text/qchar.h
+++ b/src/corelib/text/qchar.h
@@ -1,46 +1,11 @@
-/****************************************************************************
-**
-** Copyright (C) 2019 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtCore module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2020 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QCHAR_H
#define QCHAR_H
#include <QtCore/qglobal.h>
+#include <QtCore/qcompare.h>
#include <functional> // for std::hash
@@ -52,29 +17,31 @@ class QString;
struct QLatin1Char
{
public:
- Q_DECL_CONSTEXPR inline explicit QLatin1Char(char c) noexcept : ch(c) {}
- Q_DECL_CONSTEXPR inline char toLatin1() const noexcept { return ch; }
- Q_DECL_CONSTEXPR inline char16_t unicode() const noexcept { return char16_t(uchar(ch)); }
+ constexpr inline explicit QLatin1Char(char c) noexcept : ch(c) {}
+ constexpr inline char toLatin1() const noexcept { return ch; }
+ constexpr inline char16_t unicode() const noexcept { return char16_t(uchar(ch)); }
+
+ friend constexpr bool
+ comparesEqual(const QLatin1Char &lhs, const QLatin1Char &rhs) noexcept
+ { return lhs.ch == rhs.ch; }
+ friend constexpr Qt::strong_ordering
+ compareThreeWay(const QLatin1Char &lhs, const QLatin1Char &rhs) noexcept
+ { return Qt::compareThreeWay(uchar(lhs.ch), uchar(rhs.ch)); }
+ Q_DECLARE_STRONGLY_ORDERED_LITERAL_TYPE(QLatin1Char)
+
+ friend constexpr bool comparesEqual(const QLatin1Char &lhs, char rhs) noexcept
+ { return lhs.toLatin1() == rhs; }
+ friend constexpr Qt::strong_ordering
+ compareThreeWay(const QLatin1Char &lhs, char rhs) noexcept
+ { return Qt::compareThreeWay(uchar(lhs.toLatin1()), uchar(rhs)); }
+ Q_DECLARE_STRONGLY_ORDERED_LITERAL_TYPE(QLatin1Char, char)
private:
char ch;
};
-Q_DECL_CONSTEXPR inline bool operator==(char lhs, QLatin1Char rhs) noexcept { return lhs == rhs.toLatin1(); }
-Q_DECL_CONSTEXPR inline bool operator!=(char lhs, QLatin1Char rhs) noexcept { return lhs != rhs.toLatin1(); }
-Q_DECL_CONSTEXPR inline bool operator<=(char lhs, QLatin1Char rhs) noexcept { return lhs <= rhs.toLatin1(); }
-Q_DECL_CONSTEXPR inline bool operator>=(char lhs, QLatin1Char rhs) noexcept { return lhs >= rhs.toLatin1(); }
-Q_DECL_CONSTEXPR inline bool operator< (char lhs, QLatin1Char rhs) noexcept { return lhs < rhs.toLatin1(); }
-Q_DECL_CONSTEXPR inline bool operator> (char lhs, QLatin1Char rhs) noexcept { return lhs > rhs.toLatin1(); }
-
-Q_DECL_CONSTEXPR inline bool operator==(QLatin1Char lhs, char rhs) noexcept { return lhs.toLatin1() == rhs; }
-Q_DECL_CONSTEXPR inline bool operator!=(QLatin1Char lhs, char rhs) noexcept { return lhs.toLatin1() != rhs; }
-Q_DECL_CONSTEXPR inline bool operator<=(QLatin1Char lhs, char rhs) noexcept { return lhs.toLatin1() <= rhs; }
-Q_DECL_CONSTEXPR inline bool operator>=(QLatin1Char lhs, char rhs) noexcept { return lhs.toLatin1() >= rhs; }
-Q_DECL_CONSTEXPR inline bool operator< (QLatin1Char lhs, char rhs) noexcept { return lhs.toLatin1() < rhs; }
-Q_DECL_CONSTEXPR inline bool operator> (QLatin1Char lhs, char rhs) noexcept { return lhs.toLatin1() > rhs; }
-
-class Q_CORE_EXPORT QChar {
+#define QT_CHAR_FASTCALL QT7_ONLY(Q_CORE_EXPORT) QT_FASTCALL
+class QT6_ONLY(Q_CORE_EXPORT) QChar {
public:
enum SpecialCharacter {
Null = 0x0000,
@@ -91,36 +58,39 @@ public:
ByteOrderSwapped = 0xfffe,
ParagraphSeparator = 0x2029,
LineSeparator = 0x2028,
+ VisualTabCharacter = 0x2192,
LastValidCodePoint = 0x10ffff
};
- Q_DECL_CONSTEXPR QChar() noexcept : ucs(0) {}
- Q_DECL_CONSTEXPR QChar(ushort rc) noexcept : ucs(rc) {}
- Q_DECL_CONSTEXPR QChar(uchar c, uchar r) noexcept : ucs(char16_t((r << 8) | c)) {}
- Q_DECL_CONSTEXPR QChar(short rc) noexcept : ucs(char16_t(rc)) {}
- Q_DECL_CONSTEXPR QChar(uint rc) noexcept : ucs(char16_t(rc & 0xffff)) {}
- Q_DECL_CONSTEXPR QChar(int rc) noexcept : ucs(char16_t(rc & 0xffff)) {}
- Q_DECL_CONSTEXPR QChar(SpecialCharacter s) noexcept : ucs(char16_t(s)) {} // implicit
- Q_DECL_CONSTEXPR QChar(QLatin1Char ch) noexcept : ucs(ch.unicode()) {} // implicit
-#if defined(Q_COMPILER_UNICODE_STRINGS)
- Q_DECL_CONSTEXPR QChar(char16_t ch) noexcept : ucs(ch) {} // implicit
+#ifdef QT_IMPLICIT_QCHAR_CONSTRUCTION
+#define QCHAR_MAYBE_IMPLICIT Q_IMPLICIT
+#else
+#define QCHAR_MAYBE_IMPLICIT explicit
#endif
-#if defined(Q_OS_WIN)
- static_assert(sizeof(wchar_t) == sizeof(char16_t));
-#endif
-#if defined(Q_OS_WIN) || defined(Q_CLANG_QDOC)
-# if !defined(_WCHAR_T_DEFINED) || defined(_NATIVE_WCHAR_T_DEFINED)
- Q_DECL_CONSTEXPR QChar(wchar_t ch) noexcept : ucs(char16_t(ch)) {} // implicit
-# endif
+
+ constexpr Q_IMPLICIT QChar() noexcept : ucs(0) {}
+ constexpr Q_IMPLICIT QChar(ushort rc) noexcept : ucs(rc) {}
+ constexpr QCHAR_MAYBE_IMPLICIT QChar(uchar c, uchar r) noexcept : ucs(char16_t((r << 8) | c)) {}
+ constexpr Q_IMPLICIT QChar(short rc) noexcept : ucs(char16_t(rc)) {}
+ constexpr QCHAR_MAYBE_IMPLICIT QChar(uint rc) noexcept : ucs((Q_ASSERT(rc <= 0xffff), char16_t(rc))) {}
+ constexpr QCHAR_MAYBE_IMPLICIT QChar(int rc) noexcept : QChar(uint(rc)) {}
+ constexpr Q_IMPLICIT QChar(SpecialCharacter s) noexcept : ucs(char16_t(s)) {}
+ constexpr Q_IMPLICIT QChar(QLatin1Char ch) noexcept : ucs(ch.unicode()) {}
+ constexpr Q_IMPLICIT QChar(char16_t ch) noexcept : ucs(ch) {}
+#if defined(Q_OS_WIN) || defined(Q_QDOC)
+ constexpr Q_IMPLICIT QChar(wchar_t ch) noexcept : ucs(char16_t(ch)) {}
#endif
#ifndef QT_NO_CAST_FROM_ASCII
- QT_ASCII_CAST_WARN Q_DECL_CONSTEXPR QChar(char c) noexcept : ucs(uchar(c)) { }
+ // Always implicit -- allow for 'x' => QChar conversions
+ QT_ASCII_CAST_WARN constexpr Q_IMPLICIT QChar(char c) noexcept : ucs(uchar(c)) { }
#ifndef QT_RESTRICTED_CAST_FROM_ASCII
- QT_ASCII_CAST_WARN Q_DECL_CONSTEXPR QChar(uchar c) noexcept : ucs(c) { }
+ QT_ASCII_CAST_WARN constexpr QCHAR_MAYBE_IMPLICIT QChar(uchar c) noexcept : ucs(c) { }
#endif
#endif
+#undef QCHAR_MAYBE_IMPLICIT
+
static constexpr QChar fromUcs2(char16_t c) noexcept { return QChar{c}; }
static constexpr inline auto fromUcs4(char32_t c) noexcept;
@@ -353,6 +323,17 @@ public:
Script_KhitanSmallScript,
Script_Yezidi,
+ // Unicode 14.0 additions
+ Script_CyproMinoan,
+ Script_OldUyghur,
+ Script_Tangsa,
+ Script_Toto,
+ Script_Vithkuqi,
+
+ // Unicode 15.0 additions
+ Script_Kawi,
+ Script_NagMundari,
+
ScriptCount
};
@@ -394,13 +375,6 @@ public:
Joining_Transparent
};
-#if QT_DEPRECATED_SINCE(5, 3)
- enum Joining
- {
- OtherJoining, Dual, Right, Center
- };
-#endif
-
enum CombiningClass
{
Combining_BelowLeftAttached = 200,
@@ -450,26 +424,15 @@ public:
Unicode_11_0,
Unicode_12_0,
Unicode_12_1,
- Unicode_13_0
+ Unicode_13_0,
+ Unicode_14_0,
+ Unicode_15_0,
+ Unicode_15_1,
};
inline Category category() const noexcept { return QChar::category(ucs); }
inline Direction direction() const noexcept { return QChar::direction(ucs); }
inline JoiningType joiningType() const noexcept { return QChar::joiningType(ucs); }
-#if QT_DEPRECATED_SINCE(5, 3)
- QT_DEPRECATED inline Joining joining() const noexcept
- {
- switch (QChar::joiningType(ucs)) {
- case QChar::Joining_Causing: return QChar::Center;
- case QChar::Joining_Dual: return QChar::Dual;
- case QChar::Joining_Right: return QChar::Right;
- case QChar::Joining_None:
- case QChar::Joining_Left:
- case QChar::Joining_Transparent:
- default: return QChar::OtherJoining;
- }
- }
-#endif
inline unsigned char combiningClass() const noexcept { return QChar::combiningClass(ucs); }
inline QChar mirroredChar() const noexcept { return QChar(QChar::mirroredChar(ucs)); }
@@ -488,186 +451,199 @@ public:
inline UnicodeVersion unicodeVersion() const noexcept { return QChar::unicodeVersion(ucs); }
-#if QT_DEPRECATED_SINCE(5, 0)
- QT_DEPRECATED Q_DECL_CONSTEXPR inline char toAscii() const noexcept { return toLatin1(); }
-#endif
- Q_DECL_CONSTEXPR inline char toLatin1() const noexcept { return ucs > 0xff ? '\0' : char(ucs); }
- Q_DECL_CONSTEXPR inline char16_t unicode() const noexcept { return ucs; }
- Q_DECL_RELAXED_CONSTEXPR inline char16_t &unicode() noexcept { return ucs; }
+ constexpr inline char toLatin1() const noexcept { return ucs > 0xff ? '\0' : char(ucs); }
+ constexpr inline char16_t unicode() const noexcept { return ucs; }
+ constexpr inline char16_t &unicode() noexcept { return ucs; }
-#if QT_DEPRECATED_SINCE(5, 0)
- QT_DEPRECATED static Q_DECL_CONSTEXPR inline QChar fromAscii(char c) noexcept
- { return fromLatin1(c); }
-#endif
- static Q_DECL_CONSTEXPR QChar fromLatin1(char c) noexcept { return QLatin1Char(c); }
+ static constexpr QChar fromLatin1(char c) noexcept { return QLatin1Char(c); }
- Q_DECL_CONSTEXPR inline bool isNull() const noexcept { return ucs == 0; }
+ constexpr inline bool isNull() const noexcept { return ucs == 0; }
inline bool isPrint() const noexcept { return QChar::isPrint(ucs); }
- Q_DECL_CONSTEXPR inline bool isSpace() const noexcept { return QChar::isSpace(ucs); }
+ constexpr inline bool isSpace() const noexcept { return QChar::isSpace(ucs); }
inline bool isMark() const noexcept { return QChar::isMark(ucs); }
inline bool isPunct() const noexcept { return QChar::isPunct(ucs); }
inline bool isSymbol() const noexcept { return QChar::isSymbol(ucs); }
- Q_DECL_CONSTEXPR inline bool isLetter() const noexcept { return QChar::isLetter(ucs); }
- Q_DECL_CONSTEXPR inline bool isNumber() const noexcept { return QChar::isNumber(ucs); }
- Q_DECL_CONSTEXPR inline bool isLetterOrNumber() const noexcept { return QChar::isLetterOrNumber(ucs); }
- Q_DECL_CONSTEXPR inline bool isDigit() const noexcept { return QChar::isDigit(ucs); }
- Q_DECL_CONSTEXPR inline bool isLower() const noexcept { return QChar::isLower(ucs); }
- Q_DECL_CONSTEXPR inline bool isUpper() const noexcept { return QChar::isUpper(ucs); }
- Q_DECL_CONSTEXPR inline bool isTitleCase() const noexcept { return QChar::isTitleCase(ucs); }
-
- Q_DECL_CONSTEXPR inline bool isNonCharacter() const noexcept { return QChar::isNonCharacter(ucs); }
- Q_DECL_CONSTEXPR inline bool isHighSurrogate() const noexcept { return QChar::isHighSurrogate(ucs); }
- Q_DECL_CONSTEXPR inline bool isLowSurrogate() const noexcept { return QChar::isLowSurrogate(ucs); }
- Q_DECL_CONSTEXPR inline bool isSurrogate() const noexcept { return QChar::isSurrogate(ucs); }
-
- Q_DECL_CONSTEXPR inline uchar cell() const noexcept { return uchar(ucs & 0xff); }
- Q_DECL_CONSTEXPR inline uchar row() const noexcept { return uchar((ucs>>8)&0xff); }
- Q_DECL_RELAXED_CONSTEXPR inline void setCell(uchar acell) noexcept { ucs = char16_t((ucs & 0xff00) + acell); }
- Q_DECL_RELAXED_CONSTEXPR inline void setRow(uchar arow) noexcept { ucs = char16_t((char16_t(arow)<<8) + (ucs&0xff)); }
-
- static Q_DECL_CONSTEXPR inline bool isNonCharacter(char32_t ucs4) noexcept
+ constexpr inline bool isLetter() const noexcept { return QChar::isLetter(ucs); }
+ constexpr inline bool isNumber() const noexcept { return QChar::isNumber(ucs); }
+ constexpr inline bool isLetterOrNumber() const noexcept { return QChar::isLetterOrNumber(ucs); }
+ constexpr inline bool isDigit() const noexcept { return QChar::isDigit(ucs); }
+ constexpr inline bool isLower() const noexcept { return QChar::isLower(ucs); }
+ constexpr inline bool isUpper() const noexcept { return QChar::isUpper(ucs); }
+ constexpr inline bool isTitleCase() const noexcept { return QChar::isTitleCase(ucs); }
+
+ constexpr inline bool isNonCharacter() const noexcept { return QChar::isNonCharacter(ucs); }
+ constexpr inline bool isHighSurrogate() const noexcept { return QChar::isHighSurrogate(ucs); }
+ constexpr inline bool isLowSurrogate() const noexcept { return QChar::isLowSurrogate(ucs); }
+ constexpr inline bool isSurrogate() const noexcept { return QChar::isSurrogate(ucs); }
+
+ constexpr inline uchar cell() const noexcept { return uchar(ucs & 0xff); }
+ constexpr inline uchar row() const noexcept { return uchar((ucs>>8)&0xff); }
+ constexpr inline void setCell(uchar acell) noexcept { ucs = char16_t((ucs & 0xff00) + acell); }
+ constexpr inline void setRow(uchar arow) noexcept { ucs = char16_t((char16_t(arow)<<8) + (ucs&0xff)); }
+
+ static constexpr inline bool isNonCharacter(char32_t ucs4) noexcept
{
return ucs4 >= 0xfdd0 && (ucs4 <= 0xfdef || (ucs4 & 0xfffe) == 0xfffe);
}
- static Q_DECL_CONSTEXPR inline bool isHighSurrogate(char32_t ucs4) noexcept
+ static constexpr inline bool isHighSurrogate(char32_t ucs4) noexcept
{
- return ((ucs4 & 0xfffffc00) == 0xd800);
+ return (ucs4 & 0xfffffc00) == 0xd800; // 0xd800 + up to 1023 (0x3ff)
}
- static Q_DECL_CONSTEXPR inline bool isLowSurrogate(char32_t ucs4) noexcept
+ static constexpr inline bool isLowSurrogate(char32_t ucs4) noexcept
{
- return ((ucs4 & 0xfffffc00) == 0xdc00);
+ return (ucs4 & 0xfffffc00) == 0xdc00; // 0xdc00 + up to 1023 (0x3ff)
}
- static Q_DECL_CONSTEXPR inline bool isSurrogate(char32_t ucs4) noexcept
+ static constexpr inline bool isSurrogate(char32_t ucs4) noexcept
{
return (ucs4 - 0xd800u < 2048u);
}
- static Q_DECL_CONSTEXPR inline bool requiresSurrogates(char32_t ucs4) noexcept
+ static constexpr inline bool requiresSurrogates(char32_t ucs4) noexcept
{
return (ucs4 >= 0x10000);
}
- static Q_DECL_CONSTEXPR inline char32_t surrogateToUcs4(char16_t high, char16_t low) noexcept
+ static constexpr inline char32_t surrogateToUcs4(char16_t high, char16_t low) noexcept
{
+ // 0x010000 through 0x10ffff, provided params are actual high, low surrogates.
+ // 0x010000 + ((high - 0xd800) << 10) + (low - 0xdc00), optimized:
return (char32_t(high)<<10) + low - 0x35fdc00;
}
- static Q_DECL_CONSTEXPR inline char32_t surrogateToUcs4(QChar high, QChar low) noexcept
+ static constexpr inline char32_t surrogateToUcs4(QChar high, QChar low) noexcept
{
return surrogateToUcs4(high.ucs, low.ucs);
}
- static Q_DECL_CONSTEXPR inline char16_t highSurrogate(char32_t ucs4) noexcept
+ static constexpr inline char16_t highSurrogate(char32_t ucs4) noexcept
{
return char16_t((ucs4>>10) + 0xd7c0);
}
- static Q_DECL_CONSTEXPR inline char16_t lowSurrogate(char32_t ucs4) noexcept
+ static constexpr inline char16_t lowSurrogate(char32_t ucs4) noexcept
{
return char16_t(ucs4%0x400 + 0xdc00);
}
- static Category QT_FASTCALL category(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION;
- static Direction QT_FASTCALL direction(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION;
- static JoiningType QT_FASTCALL joiningType(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION;
-#if QT_DEPRECATED_SINCE(5, 3)
- QT_DEPRECATED static Joining QT_FASTCALL joining(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION;
-#endif
- static unsigned char QT_FASTCALL combiningClass(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION;
+ static Category QT_CHAR_FASTCALL category(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION;
+ static Direction QT_CHAR_FASTCALL direction(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION;
+ static JoiningType QT_CHAR_FASTCALL joiningType(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION;
+ static unsigned char QT_CHAR_FASTCALL combiningClass(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION;
- static char32_t QT_FASTCALL mirroredChar(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION;
- static bool QT_FASTCALL hasMirrored(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION;
+ static char32_t QT_CHAR_FASTCALL mirroredChar(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION;
+ static bool QT_CHAR_FASTCALL hasMirrored(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION;
- static QString QT_FASTCALL decomposition(char32_t ucs4);
- static Decomposition QT_FASTCALL decompositionTag(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION;
+ static QString QT_CHAR_FASTCALL decomposition(char32_t ucs4);
+ static Decomposition QT_CHAR_FASTCALL decompositionTag(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION;
- static int QT_FASTCALL digitValue(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION;
- static char32_t QT_FASTCALL toLower(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION;
- static char32_t QT_FASTCALL toUpper(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION;
- static char32_t QT_FASTCALL toTitleCase(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION;
- static char32_t QT_FASTCALL toCaseFolded(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION;
+ static int QT_CHAR_FASTCALL digitValue(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION;
+ static char32_t QT_CHAR_FASTCALL toLower(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION;
+ static char32_t QT_CHAR_FASTCALL toUpper(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION;
+ static char32_t QT_CHAR_FASTCALL toTitleCase(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION;
+ static char32_t QT_CHAR_FASTCALL toCaseFolded(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION;
- static Script QT_FASTCALL script(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION;
+ static Script QT_CHAR_FASTCALL script(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION;
- static UnicodeVersion QT_FASTCALL unicodeVersion(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION;
+ static UnicodeVersion QT_CHAR_FASTCALL unicodeVersion(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION;
- static UnicodeVersion QT_FASTCALL currentUnicodeVersion() noexcept Q_DECL_CONST_FUNCTION;
+ static UnicodeVersion QT_CHAR_FASTCALL currentUnicodeVersion() noexcept Q_DECL_CONST_FUNCTION;
- static bool QT_FASTCALL isPrint(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION;
- static Q_DECL_CONSTEXPR inline bool isSpace(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION
+ static bool QT_CHAR_FASTCALL isPrint(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION;
+ static constexpr inline bool isSpace(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION
{
// note that [0x09..0x0d] + 0x85 are exceptional Cc-s and must be handled explicitly
return ucs4 == 0x20 || (ucs4 <= 0x0d && ucs4 >= 0x09)
|| (ucs4 > 127 && (ucs4 == 0x85 || ucs4 == 0xa0 || QChar::isSpace_helper(ucs4)));
}
- static bool QT_FASTCALL isMark(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION;
- static bool QT_FASTCALL isPunct(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION;
- static bool QT_FASTCALL isSymbol(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION;
- static Q_DECL_CONSTEXPR inline bool isLetter(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION
+ static bool QT_CHAR_FASTCALL isMark(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION;
+ static bool QT_CHAR_FASTCALL isPunct(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION;
+ static bool QT_CHAR_FASTCALL isSymbol(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION;
+ static constexpr inline bool isLetter(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION
{
return (ucs4 >= 'A' && ucs4 <= 'z' && (ucs4 >= 'a' || ucs4 <= 'Z'))
|| (ucs4 > 127 && QChar::isLetter_helper(ucs4));
}
- static Q_DECL_CONSTEXPR inline bool isNumber(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION
+ static constexpr inline bool isNumber(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION
{ return (ucs4 <= '9' && ucs4 >= '0') || (ucs4 > 127 && QChar::isNumber_helper(ucs4)); }
- static Q_DECL_CONSTEXPR inline bool isLetterOrNumber(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION
+ static constexpr inline bool isLetterOrNumber(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION
{
return (ucs4 >= 'A' && ucs4 <= 'z' && (ucs4 >= 'a' || ucs4 <= 'Z'))
|| (ucs4 >= '0' && ucs4 <= '9')
|| (ucs4 > 127 && QChar::isLetterOrNumber_helper(ucs4));
}
- static Q_DECL_CONSTEXPR inline bool isDigit(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION
+ static constexpr inline bool isDigit(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION
{ return (ucs4 <= '9' && ucs4 >= '0') || (ucs4 > 127 && QChar::category(ucs4) == Number_DecimalDigit); }
- static Q_DECL_CONSTEXPR inline bool isLower(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION
+ static constexpr inline bool isLower(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION
{ return (ucs4 <= 'z' && ucs4 >= 'a') || (ucs4 > 127 && QChar::category(ucs4) == Letter_Lowercase); }
- static Q_DECL_CONSTEXPR inline bool isUpper(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION
+ static constexpr inline bool isUpper(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION
{ return (ucs4 <= 'Z' && ucs4 >= 'A') || (ucs4 > 127 && QChar::category(ucs4) == Letter_Uppercase); }
- static Q_DECL_CONSTEXPR inline bool isTitleCase(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION
+ static constexpr inline bool isTitleCase(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION
{ return ucs4 > 127 && QChar::category(ucs4) == Letter_Titlecase; }
+ friend constexpr bool comparesEqual(const QChar &lhs, const QChar &rhs) noexcept
+ { return lhs.ucs == rhs.ucs; }
+ friend constexpr Qt::strong_ordering
+ compareThreeWay(const QChar &lhs, const QChar &rhs) noexcept
+ { return Qt::compareThreeWay(lhs.ucs, rhs.ucs); }
+ Q_DECLARE_STRONGLY_ORDERED_LITERAL_TYPE(QChar)
+
+ friend constexpr bool comparesEqual(const QChar &lhs, std::nullptr_t) noexcept
+ { return lhs.isNull(); }
+ friend constexpr Qt::strong_ordering
+ compareThreeWay(const QChar &lhs, std::nullptr_t) noexcept
+ { return lhs.isNull() ? Qt::strong_ordering::equivalent : Qt::strong_ordering::greater; }
+ Q_DECLARE_STRONGLY_ORDERED_LITERAL_TYPE(QChar, std::nullptr_t)
+
private:
- static bool QT_FASTCALL isSpace_helper(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION;
- static bool QT_FASTCALL isLetter_helper(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION;
- static bool QT_FASTCALL isNumber_helper(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION;
- static bool QT_FASTCALL isLetterOrNumber_helper(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION;
+ static bool QT_CHAR_FASTCALL isSpace_helper(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION;
+ static bool QT_CHAR_FASTCALL isLetter_helper(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION;
+ static bool QT_CHAR_FASTCALL isNumber_helper(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION;
+ static bool QT_CHAR_FASTCALL isLetterOrNumber_helper(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION;
+
+ // defined in qstring.cpp, because we need to go via QUtf8StringView
+ static bool QT_CHAR_FASTCALL
+ equal_helper(QChar lhs, const char *rhs) noexcept Q_DECL_CONST_FUNCTION;
+ static int QT_CHAR_FASTCALL
+ compare_helper(QChar lhs, const char *rhs) noexcept Q_DECL_CONST_FUNCTION;
+
+#if !defined(QT_NO_CAST_FROM_ASCII) && !defined(QT_RESTRICTED_CAST_FROM_ASCII)
+ Q_WEAK_OVERLOAD
+ friend bool comparesEqual(const QChar &lhs, const char *rhs) noexcept
+ { return equal_helper(lhs, rhs); }
+ Q_WEAK_OVERLOAD
+ friend Qt::strong_ordering compareThreeWay(const QChar &lhs, const char *rhs) noexcept
+ {
+ const int res = compare_helper(lhs, rhs);
+ return Qt::compareThreeWay(res, 0);
+ }
+ Q_DECLARE_STRONGLY_ORDERED(QChar, const char *, Q_WEAK_OVERLOAD QT_ASCII_CAST_WARN)
+#endif // !defined(QT_NO_CAST_FROM_ASCII) && !defined(QT_RESTRICTED_CAST_FROM_ASCII)
#ifdef QT_NO_CAST_FROM_ASCII
- QChar(char c) noexcept;
- QChar(uchar c) noexcept;
+ QChar(char c) = delete;
+ QChar(uchar c) = delete;
#endif
- friend Q_DECL_CONSTEXPR bool operator==(QChar, QChar) noexcept;
- friend Q_DECL_CONSTEXPR bool operator< (QChar, QChar) noexcept;
char16_t ucs;
};
+#undef QT_CHAR_FASTCALL
-Q_DECLARE_TYPEINFO(QChar, Q_MOVABLE_TYPE);
-
-Q_DECL_CONSTEXPR inline bool operator==(QChar c1, QChar c2) noexcept { return c1.ucs == c2.ucs; }
-Q_DECL_CONSTEXPR inline bool operator< (QChar c1, QChar c2) noexcept { return c1.ucs < c2.ucs; }
-
-Q_DECL_CONSTEXPR inline bool operator!=(QChar c1, QChar c2) noexcept { return !operator==(c1, c2); }
-Q_DECL_CONSTEXPR inline bool operator>=(QChar c1, QChar c2) noexcept { return !operator< (c1, c2); }
-Q_DECL_CONSTEXPR inline bool operator> (QChar c1, QChar c2) noexcept { return operator< (c2, c1); }
-Q_DECL_CONSTEXPR inline bool operator<=(QChar c1, QChar c2) noexcept { return !operator< (c2, c1); }
-
-
-Q_DECL_CONSTEXPR inline bool operator==(QChar lhs, std::nullptr_t) noexcept { return lhs.isNull(); }
-Q_DECL_CONSTEXPR inline bool operator< (QChar, std::nullptr_t) noexcept { return false; }
-Q_DECL_CONSTEXPR inline bool operator==(std::nullptr_t, QChar rhs) noexcept { return rhs.isNull(); }
-Q_DECL_CONSTEXPR inline bool operator< (std::nullptr_t, QChar rhs) noexcept { return !rhs.isNull(); }
-
-Q_DECL_CONSTEXPR inline bool operator!=(QChar lhs, std::nullptr_t) noexcept { return !operator==(lhs, nullptr); }
-Q_DECL_CONSTEXPR inline bool operator>=(QChar lhs, std::nullptr_t) noexcept { return !operator< (lhs, nullptr); }
-Q_DECL_CONSTEXPR inline bool operator> (QChar lhs, std::nullptr_t) noexcept { return operator< (nullptr, lhs); }
-Q_DECL_CONSTEXPR inline bool operator<=(QChar lhs, std::nullptr_t) noexcept { return !operator< (nullptr, lhs); }
-
-Q_DECL_CONSTEXPR inline bool operator!=(std::nullptr_t, QChar rhs) noexcept { return !operator==(nullptr, rhs); }
-Q_DECL_CONSTEXPR inline bool operator>=(std::nullptr_t, QChar rhs) noexcept { return !operator< (nullptr, rhs); }
-Q_DECL_CONSTEXPR inline bool operator> (std::nullptr_t, QChar rhs) noexcept { return operator< (rhs, nullptr); }
-Q_DECL_CONSTEXPR inline bool operator<=(std::nullptr_t, QChar rhs) noexcept { return !operator< (rhs, nullptr); }
+Q_DECLARE_TYPEINFO(QChar, Q_PRIMITIVE_TYPE);
#ifndef QT_NO_DATASTREAM
Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, QChar);
Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QChar &);
#endif
+namespace Qt {
+inline namespace Literals {
+inline namespace StringLiterals {
+
+constexpr inline QLatin1Char operator""_L1(char ch) noexcept
+{
+ return QLatin1Char(ch);
+}
+
+} // StringLiterals
+} // Literals
+} // Qt
+
QT_END_NAMESPACE
namespace std {