20 constexpr inline explicit QLatin1Char(
char c)
noexcept : ch(c) {}
21 constexpr inline char toLatin1()
const noexcept {
return ch; }
22 constexpr inline char16_t unicode()
const noexcept {
return char16_t(uchar(ch)); }
26 {
return lhs.ch == rhs.ch; }
29 {
return Qt::compareThreeWay(uchar(lhs.ch), uchar(rhs.ch)); }
42 explicit constexpr operator
char16_t()
const noexcept {
return unicode(); }
47#define QT_CHAR_FASTCALL QT7_ONLY(Q_CORE_EXPORT) QT_FASTCALL
48class QT6_ONLY(Q_CORE_EXPORT) QChar {
50 enum SpecialCharacter {
55 CarriageReturn = 0x000d,
59 ReplacementCharacter = 0xfffd,
60 ObjectReplacementCharacter = 0xfffc,
61 ByteOrderMark = 0xfeff,
62 ByteOrderSwapped = 0xfffe,
63 ParagraphSeparator = 0x2029,
64 LineSeparator = 0x2028,
65 VisualTabCharacter = 0x2192,
66 LastValidCodePoint = 0x10ffff
69#ifdef QT_IMPLICIT_QCHAR_CONSTRUCTION
70#error This macro has been removed in Qt 6.8.
73 using is_wide_wchar_t = std::bool_constant<(
sizeof(
wchar_t) > 2)>;
74 template <
typename Char>
75 using is_implicit_conversion_char = std::disjunction<
76 std::is_same<Char, ushort>,
77 std::is_same<Char,
short>,
78 std::is_same<Char, SpecialCharacter>,
79 std::is_same<Char, QLatin1Char>,
80 std::conjunction<std::is_same<Char,
wchar_t>, std::negation<is_wide_wchar_t>>,
81 std::is_same<Char,
char16_t>
83 template <
typename Char>
84 using is_explicit_conversion_char = std::disjunction<
85 std::is_same<Char,
char32_t>,
86 std::conjunction<std::is_same<Char,
wchar_t>, is_wide_wchar_t>,
87 std::is_same<Char,
int>,
88 std::is_same<Char, uint>
90 template <
typename Char>
91 using is_conversion_char = std::disjunction<
92 is_implicit_conversion_char<Char>,
93 is_explicit_conversion_char<Char>
95 template <
typename Char>
96 using is_implicit_ascii_warn_char = std::is_same<Char,
char>;
97 template <
typename Char>
98 using is_explicit_ascii_warn_char = std::is_same<Char, uchar>;
99 template <
typename Char>
100 using if_compatible_char = std::enable_if_t<is_conversion_char<Char>::value,
bool>;
101 template <
typename Char>
102 using if_implicit_conversion_char = std::enable_if_t<is_implicit_conversion_char<Char>::value,
bool>;
103 template <
typename Char>
104 using if_explicit_conversion_char = std::enable_if_t<is_explicit_conversion_char<Char>::value,
bool>;
105 template <
typename Char>
106 using if_implicit_ascii_warn_char = std::enable_if_t<is_implicit_ascii_warn_char<Char>::value,
bool>;
107 template <
typename Char>
108 using if_explicit_ascii_warn_char = std::enable_if_t<is_explicit_ascii_warn_char<Char>::value,
bool>;
109 template <
typename Char>
110 [[maybe_unused]]
static constexpr bool is_explicit_char_v = std::disjunction_v<
111 is_explicit_conversion_char<Char>,
112 is_explicit_ascii_warn_char<Char>
115 constexpr Q_IMPLICIT QChar()
noexcept : ucs(0) {}
116#if QT_CORE_REMOVED_SINCE(6
, 9
) || defined(Q_QDOC)
117 constexpr Q_IMPLICIT QChar(ushort rc)
noexcept : ucs(rc) {}
119 constexpr explicit QChar(uchar c, uchar r)
noexcept : ucs(
char16_t((r << 8) | c)) {}
120#if QT_CORE_REMOVED_SINCE(6
, 9
) || defined(Q_QDOC)
121 constexpr Q_IMPLICIT QChar(
short rc)
noexcept : ucs(
char16_t(rc)) {}
122 constexpr explicit QChar(uint rc)
noexcept : ucs((Q_ASSERT(rc <= 0xffff),
char16_t(rc))) {}
123 constexpr explicit QChar(
int rc)
noexcept : QChar(uint(rc)) {}
124 constexpr Q_IMPLICIT QChar(SpecialCharacter s)
noexcept : ucs(
char16_t(s)) {}
125 constexpr Q_IMPLICIT QChar(QLatin1Char ch)
noexcept : ucs(ch.unicode()) {}
126 constexpr Q_IMPLICIT QChar(
char16_t ch)
noexcept : ucs(ch) {}
127#if defined(Q_OS_WIN) || defined(Q_QDOC)
128 constexpr Q_IMPLICIT QChar(
wchar_t ch)
noexcept : ucs(
char16_t(ch)) {}
131 template <
typename Char, if_implicit_conversion_char<Char> =
true>
132 constexpr Q_IMPLICIT QChar(
const Char ch)
noexcept : ucs(
char16_t(ch)) {}
133 template <
typename Char, if_explicit_conversion_char<Char> =
true>
134 constexpr explicit QChar(
const Char ch)
noexcept
135 : ucs((Q_ASSERT(
char32_t(ch) <= 0xffff),
char16_t(ch))) {}
137#ifndef QT_NO_CAST_FROM_ASCII
139#if QT_CORE_REMOVED_SINCE(6
, 9
) || defined(Q_QDOC)
140 QT_ASCII_CAST_WARN
constexpr Q_IMPLICIT QChar(
char c)
noexcept : ucs(uchar(c)) { }
142 template <
typename Char, if_implicit_ascii_warn_char<Char> =
true>
143 QT_ASCII_CAST_WARN
constexpr Q_IMPLICIT QChar(
const Char ch)
noexcept : ucs(uchar(ch)) {}
144#ifndef QT_RESTRICTED_CAST_FROM_ASCII
145#if QT_CORE_REMOVED_SINCE(6
, 9
) || defined(Q_QDOC)
146 QT_ASCII_CAST_WARN
constexpr explicit QChar(uchar c)
noexcept : ucs(c) { }
148 template <
typename Char, if_explicit_ascii_warn_char<Char> =
true>
149 QT_ASCII_CAST_WARN
constexpr explicit QChar(
const Char c)
noexcept : ucs(c) { }
153 static constexpr QChar fromUcs2(
char16_t c)
noexcept {
return QChar{c}; }
154 [[nodiscard]]
static constexpr inline auto fromUcs4(
char32_t c)
noexcept
158 [[nodiscard]]
constexpr qsizetype size()
const noexcept {
return chars[1] ? 2 : 1; }
159 [[nodiscard]]
constexpr const char16_t *data()
const noexcept {
return chars; }
160 [[nodiscard]]
constexpr const char16_t *begin()
const noexcept {
return chars; }
161 [[nodiscard]]
constexpr const char16_t *end()
const noexcept {
return begin() + size(); }
163 return requiresSurrogates(c) ? R{{QChar::highSurrogate(c),
164 QChar::lowSurrogate(c)}} :
165 R{{
char16_t(c), u'\0'}} ;
173 Mark_SpacingCombining,
196 Punctuation_Connector,
200 Punctuation_InitialQuote,
201 Punctuation_FinalQuote,
242 Script_CanadianAboriginal,
304 Script_EgyptianHieroglyphs,
310 Script_ImperialAramaic,
311 Script_OldSouthArabian,
312 Script_InscriptionalParthian,
313 Script_InscriptionalPahlavi,
324 Script_MeroiticCursive,
325 Script_MeroiticHieroglyphs,
332 Script_CaucasianAlbanian,
345 Script_OldNorthArabian,
350 Script_PsalterPahlavi,
358 Script_AnatolianHieroglyphs,
376 Script_ZanabazarSquare,
381 Script_HanifiRohingya,
388 Script_NyiakengPuachueHmong,
394 Script_KhitanSmallScript,
428 DirL, DirR, DirEN, DirES, DirET, DirAN, DirCS, DirB, DirS, DirWS, DirON,
429 DirLRE, DirLRO, DirAL, DirRLE, DirRLO, DirPDF, DirNSM, DirBN,
430 DirLRI, DirRLI, DirFSI, DirPDI
466 Combining_BelowLeftAttached = 200,
467 Combining_BelowAttached = 202,
468 Combining_BelowRightAttached = 204,
469 Combining_LeftAttached = 208,
470 Combining_RightAttached = 210,
471 Combining_AboveLeftAttached = 212,
472 Combining_AboveAttached = 214,
473 Combining_AboveRightAttached = 216,
475 Combining_BelowLeft = 218,
476 Combining_Below = 220,
477 Combining_BelowRight = 222,
478 Combining_Left = 224,
479 Combining_Right = 226,
480 Combining_AboveLeft = 228,
481 Combining_Above = 230,
482 Combining_AboveRight = 232,
484 Combining_DoubleBelow = 233,
485 Combining_DoubleAbove = 234,
486 Combining_IotaSubscript = 240
489 enum UnicodeVersion {
521 Category category()
const noexcept {
return QChar::category(
char32_t(ucs)); }
522 Direction direction()
const noexcept {
return QChar::direction(
char32_t(ucs)); }
523 JoiningType joiningType()
const noexcept {
return QChar::joiningType(
char32_t(ucs)); }
524 unsigned char combiningClass()
const noexcept {
return QChar::combiningClass(
char32_t(ucs)); }
526 QChar mirroredChar()
const noexcept {
return QChar(QChar::mirroredChar(
char32_t(ucs))); }
527 bool hasMirrored()
const noexcept {
return QChar::hasMirrored(
char32_t(ucs)); }
529 QString decomposition()
const;
530 Decomposition decompositionTag()
const noexcept {
return QChar::decompositionTag(
char32_t(ucs)); }
532 int digitValue()
const noexcept {
return QChar::digitValue(
char32_t(ucs)); }
533 QChar toLower()
const noexcept {
return QChar(QChar::toLower(
char32_t(ucs))); }
534 QChar toUpper()
const noexcept {
return QChar(QChar::toUpper(
char32_t(ucs))); }
535 QChar toTitleCase()
const noexcept {
return QChar(QChar::toTitleCase(
char32_t(ucs))); }
536 QChar toCaseFolded()
const noexcept {
return QChar(QChar::toCaseFolded(
char32_t(ucs))); }
538 Script script()
const noexcept {
return QChar::script(
char32_t(ucs)); }
540 UnicodeVersion unicodeVersion()
const noexcept {
return QChar::unicodeVersion(
char32_t(ucs)); }
542 constexpr inline char toLatin1()
const noexcept {
return ucs > 0xff ?
'\0' :
char(ucs); }
543 constexpr inline char16_t unicode()
const noexcept {
return ucs; }
544 constexpr inline char16_t &unicode()
noexcept {
return ucs; }
546 static constexpr QChar fromLatin1(
char c)
noexcept {
return QLatin1Char(c); }
548 constexpr inline bool isNull()
const noexcept {
return ucs == 0; }
550 bool isPrint()
const noexcept {
return QChar::isPrint(
char32_t(ucs)); }
551 constexpr bool isSpace()
const noexcept {
return QChar::isSpace(
char32_t(ucs)); }
552 bool isMark()
const noexcept {
return QChar::isMark(
char32_t(ucs)); }
553 bool isPunct()
const noexcept {
return QChar::isPunct(
char32_t(ucs)); }
554 bool isSymbol()
const noexcept {
return QChar::isSymbol(
char32_t(ucs)); }
555 constexpr bool isLetter()
const noexcept {
return QChar::isLetter(
char32_t(ucs)); }
556 constexpr bool isNumber()
const noexcept {
return QChar::isNumber(
char32_t(ucs)); }
557 constexpr bool isLetterOrNumber()
const noexcept {
return QChar::isLetterOrNumber(
char32_t(ucs)); }
558 constexpr bool isDigit()
const noexcept {
return QChar::isDigit(
char32_t(ucs)); }
559 constexpr bool isLower()
const noexcept {
return QChar::isLower(
char32_t(ucs)); }
560 constexpr bool isUpper()
const noexcept {
return QChar::isUpper(
char32_t(ucs)); }
561 constexpr bool isTitleCase()
const noexcept {
return QChar::isTitleCase(
char32_t(ucs)); }
563 constexpr bool isNonCharacter()
const noexcept {
return QChar::isNonCharacter(
char32_t(ucs)); }
564 constexpr bool isHighSurrogate()
const noexcept {
return QChar::isHighSurrogate(
char32_t(ucs)); }
565 constexpr bool isLowSurrogate()
const noexcept {
return QChar::isLowSurrogate(
char32_t(ucs)); }
566 constexpr bool isSurrogate()
const noexcept {
return QChar::isSurrogate(
char32_t(ucs)); }
568 constexpr inline uchar cell()
const noexcept {
return uchar(ucs & 0xff); }
569 constexpr inline uchar row()
const noexcept {
return uchar((ucs>>8)&0xff); }
570 constexpr inline void setCell(uchar acell)
noexcept { ucs =
char16_t((ucs & 0xff00) + acell); }
571 constexpr inline void setRow(uchar arow)
noexcept { ucs =
char16_t((
char16_t(arow)<<8) + (ucs&0xff)); }
573 static constexpr inline bool isNonCharacter(
char32_t ucs4)
noexcept
575 return ucs4 >= 0xfdd0 && (ucs4 <= 0xfdef || (ucs4 & 0xfffe) == 0xfffe);
577 static constexpr inline bool isHighSurrogate(
char32_t ucs4)
noexcept
579 return (ucs4 & 0xfffffc00) == 0xd800;
581 static constexpr inline bool isLowSurrogate(
char32_t ucs4)
noexcept
583 return (ucs4 & 0xfffffc00) == 0xdc00;
585 static constexpr inline bool isSurrogate(
char32_t ucs4)
noexcept
587 return (ucs4 - 0xd800u < 2048u);
589 static constexpr inline bool requiresSurrogates(
char32_t ucs4)
noexcept
591 return (ucs4 >= 0x10000);
593 static constexpr inline char32_t surrogateToUcs4(
char16_t high,
char16_t low)
noexcept
597 return (
char32_t(high)<<10) + low - 0x35fdc00;
599 static constexpr inline char32_t surrogateToUcs4(QChar high, QChar low)
noexcept
601 return surrogateToUcs4(high.ucs, low.ucs);
603 static constexpr inline char16_t highSurrogate(
char32_t ucs4)
noexcept
605 return char16_t((ucs4>>10) + 0xd7c0);
607 static constexpr inline char16_t lowSurrogate(
char32_t ucs4)
noexcept
609 return char16_t(ucs4%0x400 + 0xdc00);
612 Q_DECL_CONST_FUNCTION
static Category
QT_CHAR_FASTCALL category(
char32_t ucs4)
noexcept;
613 Q_DECL_CONST_FUNCTION
static Direction
QT_CHAR_FASTCALL direction(
char32_t ucs4)
noexcept;
614 Q_DECL_CONST_FUNCTION
static JoiningType
QT_CHAR_FASTCALL joiningType(
char32_t ucs4)
noexcept;
615 Q_DECL_CONST_FUNCTION
static unsigned char QT_CHAR_FASTCALL combiningClass(
char32_t ucs4)
noexcept;
617 Q_DECL_CONST_FUNCTION
static char32_t QT_CHAR_FASTCALL mirroredChar(
char32_t ucs4)
noexcept;
618 Q_DECL_CONST_FUNCTION
static bool QT_CHAR_FASTCALL hasMirrored(
char32_t ucs4)
noexcept;
621 Q_DECL_CONST_FUNCTION
static Decomposition
QT_CHAR_FASTCALL decompositionTag(
char32_t ucs4)
noexcept;
623 Q_DECL_CONST_FUNCTION
static int QT_CHAR_FASTCALL digitValue(
char32_t ucs4)
noexcept;
624 Q_DECL_CONST_FUNCTION
static char32_t QT_CHAR_FASTCALL toLower(
char32_t ucs4)
noexcept;
625 Q_DECL_CONST_FUNCTION
static char32_t QT_CHAR_FASTCALL toUpper(
char32_t ucs4)
noexcept;
626 Q_DECL_CONST_FUNCTION
static char32_t QT_CHAR_FASTCALL toTitleCase(
char32_t ucs4)
noexcept;
627 Q_DECL_CONST_FUNCTION
static char32_t QT_CHAR_FASTCALL toCaseFolded(
char32_t ucs4)
noexcept;
629 Q_DECL_CONST_FUNCTION
static Script
QT_CHAR_FASTCALL script(
char32_t ucs4)
noexcept;
631 Q_DECL_CONST_FUNCTION
static UnicodeVersion
QT_CHAR_FASTCALL unicodeVersion(
char32_t ucs4)
noexcept;
633 Q_DECL_CONST_FUNCTION
static UnicodeVersion
QT_CHAR_FASTCALL currentUnicodeVersion()
noexcept;
635 Q_DECL_CONST_FUNCTION
static bool QT_CHAR_FASTCALL isPrint(
char32_t ucs4)
noexcept;
636 Q_DECL_CONST_FUNCTION
static constexpr inline bool isSpace(
char32_t ucs4)
noexcept
639 return ucs4 == 0x20 || (ucs4 <= 0x0d && ucs4 >= 0x09)
640 || (ucs4 > 127 && (ucs4 == 0x85 || ucs4 == 0xa0 || QChar::isSpace_helper(ucs4)));
642 Q_DECL_CONST_FUNCTION
static bool QT_CHAR_FASTCALL isMark(
char32_t ucs4)
noexcept;
643 Q_DECL_CONST_FUNCTION
static bool QT_CHAR_FASTCALL isPunct(
char32_t ucs4)
noexcept;
644 Q_DECL_CONST_FUNCTION
static bool QT_CHAR_FASTCALL isSymbol(
char32_t ucs4)
noexcept;
645 Q_DECL_CONST_FUNCTION
static constexpr inline bool isLetter(
char32_t ucs4)
noexcept
647 return (ucs4 >=
'A' && ucs4 <=
'z' && (ucs4 >=
'a' || ucs4 <=
'Z'))
648 || (ucs4 > 127 && QChar::isLetter_helper(ucs4));
650 Q_DECL_CONST_FUNCTION
static constexpr inline bool isNumber(
char32_t ucs4)
noexcept
651 {
return (ucs4 <=
'9' && ucs4 >=
'0') || (ucs4 > 127 && QChar::isNumber_helper(ucs4)); }
652 Q_DECL_CONST_FUNCTION
static constexpr inline bool isLetterOrNumber(
char32_t ucs4)
noexcept
654 return (ucs4 >=
'A' && ucs4 <=
'z' && (ucs4 >=
'a' || ucs4 <=
'Z'))
655 || (ucs4 >=
'0' && ucs4 <=
'9')
656 || (ucs4 > 127 && QChar::isLetterOrNumber_helper(ucs4));
658 Q_DECL_CONST_FUNCTION
static constexpr inline bool isDigit(
char32_t ucs4)
noexcept
659 {
return (ucs4 <=
'9' && ucs4 >=
'0') || (ucs4 > 127 && QChar::category(ucs4) == Number_DecimalDigit); }
660 Q_DECL_CONST_FUNCTION
static constexpr inline bool isLower(
char32_t ucs4)
noexcept
661 {
return (ucs4 <=
'z' && ucs4 >=
'a') || (ucs4 > 127 && QChar::category(ucs4) == Letter_Lowercase); }
662 Q_DECL_CONST_FUNCTION
static constexpr inline bool isUpper(
char32_t ucs4)
noexcept
663 {
return (ucs4 <=
'Z' && ucs4 >=
'A') || (ucs4 > 127 && QChar::category(ucs4) == Letter_Uppercase); }
664 Q_DECL_CONST_FUNCTION
static constexpr inline bool isTitleCase(
char32_t ucs4)
noexcept
665 {
return ucs4 > 127 && QChar::category(ucs4) == Letter_Titlecase; }
667 friend constexpr bool comparesEqual(
const QChar &lhs,
const QChar &rhs)
noexcept
668 {
return lhs.ucs == rhs.ucs; }
669 friend constexpr Qt::strong_ordering
670 compareThreeWay(
const QChar &lhs,
const QChar &rhs)
noexcept
671 {
return Qt::compareThreeWay(lhs.ucs, rhs.ucs); }
672 Q_DECLARE_STRONGLY_ORDERED_LITERAL_TYPE(QChar)
674 friend constexpr bool comparesEqual(
const QChar &lhs, std::nullptr_t)
noexcept
675 {
return lhs.isNull(); }
676 friend constexpr Qt::strong_ordering
677 compareThreeWay(
const QChar &lhs, std::nullptr_t)
noexcept
678 {
return lhs.isNull() ? Qt::strong_ordering::equivalent : Qt::strong_ordering::greater; }
679 Q_DECLARE_STRONGLY_ORDERED_LITERAL_TYPE(QChar, std::nullptr_t)
682 Q_DECL_CONST_FUNCTION
static bool QT_CHAR_FASTCALL isSpace_helper(
char32_t ucs4)
noexcept;
683 Q_DECL_CONST_FUNCTION
static bool QT_CHAR_FASTCALL isLetter_helper(
char32_t ucs4)
noexcept;
684 Q_DECL_CONST_FUNCTION
static bool QT_CHAR_FASTCALL isNumber_helper(
char32_t ucs4)
noexcept;
685 Q_DECL_CONST_FUNCTION
static bool QT_CHAR_FASTCALL isLetterOrNumber_helper(
char32_t ucs4)
noexcept;
689 Q_DECL_CONST_FUNCTION equal_helper(QChar lhs,
const char *rhs)
noexcept;
691 Q_DECL_CONST_FUNCTION compare_helper(QChar lhs,
const char *rhs)
noexcept;
693#if !defined(QT_NO_CAST_FROM_ASCII) && !defined(QT_RESTRICTED_CAST_FROM_ASCII)
695 friend bool comparesEqual(
const QChar &lhs,
const char *rhs)
noexcept
696 {
return equal_helper(lhs, rhs); }
698 friend Qt::strong_ordering compareThreeWay(
const QChar &lhs,
const char *rhs)
noexcept
700 const int res = compare_helper(lhs, rhs);
701 return Qt::compareThreeWay(res, 0);
703 Q_DECLARE_STRONGLY_ORDERED(QChar,
const char *, Q_WEAK_OVERLOAD QT_ASCII_CAST_WARN)