19 constexpr inline explicit QLatin1Char(
char c)
noexcept : ch(c) {}
20 constexpr inline char toLatin1()
const noexcept {
return ch; }
21 constexpr inline char16_t unicode()
const noexcept {
return char16_t(uchar(ch)); }
25 {
return lhs.ch == rhs.ch; }
28 {
return Qt::compareThreeWay(uchar(lhs.ch), uchar(rhs.ch)); }
41 explicit constexpr operator
char16_t()
const noexcept {
return unicode(); }
46#define QT_CHAR_FASTCALL QT7_ONLY(Q_CORE_EXPORT) QT_FASTCALL
47class QT6_ONLY(Q_CORE_EXPORT) QChar {
49 enum SpecialCharacter {
54 CarriageReturn = 0x000d,
58 ReplacementCharacter = 0xfffd,
59 ObjectReplacementCharacter = 0xfffc,
60 ByteOrderMark = 0xfeff,
61 ByteOrderSwapped = 0xfffe,
62 ParagraphSeparator = 0x2029,
63 LineSeparator = 0x2028,
64 VisualTabCharacter = 0x2192,
65 LastValidCodePoint = 0x10ffff
68#ifdef QT_IMPLICIT_QCHAR_CONSTRUCTION
69#error This macro has been removed in Qt 6.8.
72 using is_wide_wchar_t = std::bool_constant<(
sizeof(
wchar_t) > 2)>;
73 template <
typename Char>
74 using is_implicit_conversion_char = std::disjunction<
75 std::is_same<Char, ushort>,
76 std::is_same<Char,
short>,
77 std::is_same<Char, SpecialCharacter>,
78 std::is_same<Char, QLatin1Char>,
79 std::conjunction<std::is_same<Char,
wchar_t>, std::negation<is_wide_wchar_t>>,
80 std::is_same<Char,
char16_t>
82 template <
typename Char>
83 using is_explicit_conversion_char = std::disjunction<
84 std::is_same<Char,
char32_t>,
85 std::conjunction<std::is_same<Char,
wchar_t>, is_wide_wchar_t>,
86 std::is_same<Char,
int>,
87 std::is_same<Char, uint>
89 template <
typename Char>
90 using is_conversion_char = std::disjunction<
91 is_implicit_conversion_char<Char>,
92 is_explicit_conversion_char<Char>
94 template <
typename Char>
95 using is_implicit_ascii_warn_char = std::is_same<Char,
char>;
96 template <
typename Char>
97 using is_explicit_ascii_warn_char = std::is_same<Char, uchar>;
98 template <
typename Char>
99 using if_compatible_char = std::enable_if_t<is_conversion_char<Char>::value,
bool>;
100 template <
typename Char>
101 using if_implicit_conversion_char = std::enable_if_t<is_implicit_conversion_char<Char>::value,
bool>;
102 template <
typename Char>
103 using if_explicit_conversion_char = std::enable_if_t<is_explicit_conversion_char<Char>::value,
bool>;
104 template <
typename Char>
105 using if_implicit_ascii_warn_char = std::enable_if_t<is_implicit_ascii_warn_char<Char>::value,
bool>;
106 template <
typename Char>
107 using if_explicit_ascii_warn_char = std::enable_if_t<is_explicit_ascii_warn_char<Char>::value,
bool>;
108 template <
typename Char>
109 [[maybe_unused]]
static constexpr bool is_explicit_char_v = std::disjunction_v<
110 is_explicit_conversion_char<Char>,
111 is_explicit_ascii_warn_char<Char>
114 constexpr Q_IMPLICIT QChar()
noexcept : ucs(0) {}
115#if QT_CORE_REMOVED_SINCE(6
, 9
) || defined(Q_QDOC)
116 constexpr Q_IMPLICIT QChar(ushort rc)
noexcept : ucs(rc) {}
118 constexpr explicit QChar(uchar c, uchar r)
noexcept : ucs(
char16_t((r << 8) | c)) {}
119#if QT_CORE_REMOVED_SINCE(6
, 9
) || defined(Q_QDOC)
120 constexpr Q_IMPLICIT QChar(
short rc)
noexcept : ucs(
char16_t(rc)) {}
121 constexpr explicit QChar(uint rc)
noexcept : ucs((Q_ASSERT(rc <= 0xffff),
char16_t(rc))) {}
122 constexpr explicit QChar(
int rc)
noexcept : QChar(uint(rc)) {}
123 constexpr Q_IMPLICIT QChar(SpecialCharacter s)
noexcept : ucs(
char16_t(s)) {}
124 constexpr Q_IMPLICIT QChar(QLatin1Char ch)
noexcept : ucs(ch.unicode()) {}
125 constexpr Q_IMPLICIT QChar(
char16_t ch)
noexcept : ucs(ch) {}
126#if defined(Q_OS_WIN) || defined(Q_QDOC)
127 constexpr Q_IMPLICIT QChar(
wchar_t ch)
noexcept : ucs(
char16_t(ch)) {}
130 template <
typename Char, if_implicit_conversion_char<Char> =
true>
131 constexpr Q_IMPLICIT QChar(
const Char ch)
noexcept : ucs(
char16_t(ch)) {}
132 template <
typename Char, if_explicit_conversion_char<Char> =
true>
133 constexpr explicit QChar(
const Char ch)
noexcept
134 : ucs((Q_ASSERT(
char32_t(ch) <= 0xffff),
char16_t(ch))) {}
136#ifndef QT_NO_CAST_FROM_ASCII
138#if QT_CORE_REMOVED_SINCE(6
, 9
) || defined(Q_QDOC)
139 QT_ASCII_CAST_WARN
constexpr Q_IMPLICIT QChar(
char c)
noexcept : ucs(uchar(c)) { }
141 template <
typename Char, if_implicit_ascii_warn_char<Char> =
true>
142 QT_ASCII_CAST_WARN
constexpr Q_IMPLICIT QChar(
const Char ch)
noexcept : ucs(uchar(ch)) {}
143#ifndef QT_RESTRICTED_CAST_FROM_ASCII
144#if QT_CORE_REMOVED_SINCE(6
, 9
) || defined(Q_QDOC)
145 QT_ASCII_CAST_WARN
constexpr explicit QChar(uchar c)
noexcept : ucs(c) { }
147 template <
typename Char, if_explicit_ascii_warn_char<Char> =
true>
148 QT_ASCII_CAST_WARN
constexpr explicit QChar(
const Char c)
noexcept : ucs(c) { }
152 static constexpr QChar fromUcs2(
char16_t c)
noexcept {
return QChar{c}; }
153 static constexpr inline auto fromUcs4(
char32_t c)
noexcept;
160 Mark_SpacingCombining,
183 Punctuation_Connector,
187 Punctuation_InitialQuote,
188 Punctuation_FinalQuote,
229 Script_CanadianAboriginal,
291 Script_EgyptianHieroglyphs,
297 Script_ImperialAramaic,
298 Script_OldSouthArabian,
299 Script_InscriptionalParthian,
300 Script_InscriptionalPahlavi,
311 Script_MeroiticCursive,
312 Script_MeroiticHieroglyphs,
319 Script_CaucasianAlbanian,
332 Script_OldNorthArabian,
337 Script_PsalterPahlavi,
345 Script_AnatolianHieroglyphs,
363 Script_ZanabazarSquare,
368 Script_HanifiRohingya,
375 Script_NyiakengPuachueHmong,
381 Script_KhitanSmallScript,
409 DirL, DirR, DirEN, DirES, DirET, DirAN, DirCS, DirB, DirS, DirWS, DirON,
410 DirLRE, DirLRO, DirAL, DirRLE, DirRLO, DirPDF, DirNSM, DirBN,
411 DirLRI, DirRLI, DirFSI, DirPDI
447 Combining_BelowLeftAttached = 200,
448 Combining_BelowAttached = 202,
449 Combining_BelowRightAttached = 204,
450 Combining_LeftAttached = 208,
451 Combining_RightAttached = 210,
452 Combining_AboveLeftAttached = 212,
453 Combining_AboveAttached = 214,
454 Combining_AboveRightAttached = 216,
456 Combining_BelowLeft = 218,
457 Combining_Below = 220,
458 Combining_BelowRight = 222,
459 Combining_Left = 224,
460 Combining_Right = 226,
461 Combining_AboveLeft = 228,
462 Combining_Above = 230,
463 Combining_AboveRight = 232,
465 Combining_DoubleBelow = 233,
466 Combining_DoubleAbove = 234,
467 Combining_IotaSubscript = 240
470 enum UnicodeVersion {
501 inline Category category()
const noexcept {
return QChar::category(ucs); }
502 inline Direction direction()
const noexcept {
return QChar::direction(ucs); }
503 inline JoiningType joiningType()
const noexcept {
return QChar::joiningType(ucs); }
504 inline unsigned char combiningClass()
const noexcept {
return QChar::combiningClass(ucs); }
506 inline QChar mirroredChar()
const noexcept {
return QChar(QChar::mirroredChar(ucs)); }
507 inline bool hasMirrored()
const noexcept {
return QChar::hasMirrored(ucs); }
509 QString decomposition()
const;
510 inline Decomposition decompositionTag()
const noexcept {
return QChar::decompositionTag(ucs); }
512 inline int digitValue()
const noexcept {
return QChar::digitValue(ucs); }
513 inline QChar toLower()
const noexcept {
return QChar(QChar::toLower(ucs)); }
514 inline QChar toUpper()
const noexcept {
return QChar(QChar::toUpper(ucs)); }
515 inline QChar toTitleCase()
const noexcept {
return QChar(QChar::toTitleCase(ucs)); }
516 inline QChar toCaseFolded()
const noexcept {
return QChar(QChar::toCaseFolded(ucs)); }
518 inline Script script()
const noexcept {
return QChar::script(ucs); }
520 inline UnicodeVersion unicodeVersion()
const noexcept {
return QChar::unicodeVersion(ucs); }
522 constexpr inline char toLatin1()
const noexcept {
return ucs > 0xff ?
'\0' :
char(ucs); }
523 constexpr inline char16_t unicode()
const noexcept {
return ucs; }
524 constexpr inline char16_t &unicode()
noexcept {
return ucs; }
526 static constexpr QChar fromLatin1(
char c)
noexcept {
return QLatin1Char(c); }
528 constexpr inline bool isNull()
const noexcept {
return ucs == 0; }
530 inline bool isPrint()
const noexcept {
return QChar::isPrint(ucs); }
531 constexpr inline bool isSpace()
const noexcept {
return QChar::isSpace(ucs); }
532 inline bool isMark()
const noexcept {
return QChar::isMark(ucs); }
533 inline bool isPunct()
const noexcept {
return QChar::isPunct(ucs); }
534 inline bool isSymbol()
const noexcept {
return QChar::isSymbol(ucs); }
535 constexpr inline bool isLetter()
const noexcept {
return QChar::isLetter(ucs); }
536 constexpr inline bool isNumber()
const noexcept {
return QChar::isNumber(ucs); }
537 constexpr inline bool isLetterOrNumber()
const noexcept {
return QChar::isLetterOrNumber(ucs); }
538 constexpr inline bool isDigit()
const noexcept {
return QChar::isDigit(ucs); }
539 constexpr inline bool isLower()
const noexcept {
return QChar::isLower(ucs); }
540 constexpr inline bool isUpper()
const noexcept {
return QChar::isUpper(ucs); }
541 constexpr inline bool isTitleCase()
const noexcept {
return QChar::isTitleCase(ucs); }
543 constexpr inline bool isNonCharacter()
const noexcept {
return QChar::isNonCharacter(ucs); }
544 constexpr inline bool isHighSurrogate()
const noexcept {
return QChar::isHighSurrogate(ucs); }
545 constexpr inline bool isLowSurrogate()
const noexcept {
return QChar::isLowSurrogate(ucs); }
546 constexpr inline bool isSurrogate()
const noexcept {
return QChar::isSurrogate(ucs); }
548 constexpr inline uchar cell()
const noexcept {
return uchar(ucs & 0xff); }
549 constexpr inline uchar row()
const noexcept {
return uchar((ucs>>8)&0xff); }
550 constexpr inline void setCell(uchar acell)
noexcept { ucs =
char16_t((ucs & 0xff00) + acell); }
551 constexpr inline void setRow(uchar arow)
noexcept { ucs =
char16_t((
char16_t(arow)<<8) + (ucs&0xff)); }
553 static constexpr inline bool isNonCharacter(
char32_t ucs4)
noexcept
555 return ucs4 >= 0xfdd0 && (ucs4 <= 0xfdef || (ucs4 & 0xfffe) == 0xfffe);
557 static constexpr inline bool isHighSurrogate(
char32_t ucs4)
noexcept
559 return (ucs4 & 0xfffffc00) == 0xd800;
561 static constexpr inline bool isLowSurrogate(
char32_t ucs4)
noexcept
563 return (ucs4 & 0xfffffc00) == 0xdc00;
565 static constexpr inline bool isSurrogate(
char32_t ucs4)
noexcept
567 return (ucs4 - 0xd800u < 2048u);
569 static constexpr inline bool requiresSurrogates(
char32_t ucs4)
noexcept
571 return (ucs4 >= 0x10000);
573 static constexpr inline char32_t surrogateToUcs4(
char16_t high,
char16_t low)
noexcept
577 return (
char32_t(high)<<10) + low - 0x35fdc00;
579 static constexpr inline char32_t surrogateToUcs4(QChar high, QChar low)
noexcept
581 return surrogateToUcs4(high.ucs, low.ucs);
583 static constexpr inline char16_t highSurrogate(
char32_t ucs4)
noexcept
585 return char16_t((ucs4>>10) + 0xd7c0);
587 static constexpr inline char16_t lowSurrogate(
char32_t ucs4)
noexcept
589 return char16_t(ucs4%0x400 + 0xdc00);
592 static Category
QT_CHAR_FASTCALL category(
char32_t ucs4)
noexcept Q_DECL_CONST_FUNCTION;
593 static Direction
QT_CHAR_FASTCALL direction(
char32_t ucs4)
noexcept Q_DECL_CONST_FUNCTION;
594 static JoiningType
QT_CHAR_FASTCALL joiningType(
char32_t ucs4)
noexcept Q_DECL_CONST_FUNCTION;
595 static unsigned char QT_CHAR_FASTCALL combiningClass(
char32_t ucs4)
noexcept Q_DECL_CONST_FUNCTION;
597 static char32_t QT_CHAR_FASTCALL mirroredChar(
char32_t ucs4)
noexcept Q_DECL_CONST_FUNCTION;
598 static bool QT_CHAR_FASTCALL hasMirrored(
char32_t ucs4)
noexcept Q_DECL_CONST_FUNCTION;
601 static Decomposition
QT_CHAR_FASTCALL decompositionTag(
char32_t ucs4)
noexcept Q_DECL_CONST_FUNCTION;
603 static int QT_CHAR_FASTCALL digitValue(
char32_t ucs4)
noexcept Q_DECL_CONST_FUNCTION;
604 static char32_t QT_CHAR_FASTCALL toLower(
char32_t ucs4)
noexcept Q_DECL_CONST_FUNCTION;
605 static char32_t QT_CHAR_FASTCALL toUpper(
char32_t ucs4)
noexcept Q_DECL_CONST_FUNCTION;
606 static char32_t QT_CHAR_FASTCALL toTitleCase(
char32_t ucs4)
noexcept Q_DECL_CONST_FUNCTION;
607 static char32_t QT_CHAR_FASTCALL toCaseFolded(
char32_t ucs4)
noexcept Q_DECL_CONST_FUNCTION;
609 static Script
QT_CHAR_FASTCALL script(
char32_t ucs4)
noexcept Q_DECL_CONST_FUNCTION;
611 static UnicodeVersion
QT_CHAR_FASTCALL unicodeVersion(
char32_t ucs4)
noexcept Q_DECL_CONST_FUNCTION;
613 static UnicodeVersion
QT_CHAR_FASTCALL currentUnicodeVersion()
noexcept Q_DECL_CONST_FUNCTION;
615 static bool QT_CHAR_FASTCALL isPrint(
char32_t ucs4)
noexcept Q_DECL_CONST_FUNCTION;
616 static constexpr inline bool isSpace(
char32_t ucs4)
noexcept Q_DECL_CONST_FUNCTION
619 return ucs4 == 0x20 || (ucs4 <= 0x0d && ucs4 >= 0x09)
620 || (ucs4 > 127 && (ucs4 == 0x85 || ucs4 == 0xa0 || QChar::isSpace_helper(ucs4)));
622 static bool QT_CHAR_FASTCALL isMark(
char32_t ucs4)
noexcept Q_DECL_CONST_FUNCTION;
623 static bool QT_CHAR_FASTCALL isPunct(
char32_t ucs4)
noexcept Q_DECL_CONST_FUNCTION;
624 static bool QT_CHAR_FASTCALL isSymbol(
char32_t ucs4)
noexcept Q_DECL_CONST_FUNCTION;
625 static constexpr inline bool isLetter(
char32_t ucs4)
noexcept Q_DECL_CONST_FUNCTION
627 return (ucs4 >=
'A' && ucs4 <=
'z' && (ucs4 >=
'a' || ucs4 <=
'Z'))
628 || (ucs4 > 127 && QChar::isLetter_helper(ucs4));
630 static constexpr inline bool isNumber(
char32_t ucs4)
noexcept Q_DECL_CONST_FUNCTION
631 {
return (ucs4 <=
'9' && ucs4 >=
'0') || (ucs4 > 127 && QChar::isNumber_helper(ucs4)); }
632 static constexpr inline bool isLetterOrNumber(
char32_t ucs4)
noexcept Q_DECL_CONST_FUNCTION
634 return (ucs4 >=
'A' && ucs4 <=
'z' && (ucs4 >=
'a' || ucs4 <=
'Z'))
635 || (ucs4 >=
'0' && ucs4 <=
'9')
636 || (ucs4 > 127 && QChar::isLetterOrNumber_helper(ucs4));
638 static constexpr inline bool isDigit(
char32_t ucs4)
noexcept Q_DECL_CONST_FUNCTION
639 {
return (ucs4 <=
'9' && ucs4 >=
'0') || (ucs4 > 127 && QChar::category(ucs4) == Number_DecimalDigit); }
640 static constexpr inline bool isLower(
char32_t ucs4)
noexcept Q_DECL_CONST_FUNCTION
641 {
return (ucs4 <=
'z' && ucs4 >=
'a') || (ucs4 > 127 && QChar::category(ucs4) == Letter_Lowercase); }
642 static constexpr inline bool isUpper(
char32_t ucs4)
noexcept Q_DECL_CONST_FUNCTION
643 {
return (ucs4 <=
'Z' && ucs4 >=
'A') || (ucs4 > 127 && QChar::category(ucs4) == Letter_Uppercase); }
644 static constexpr inline bool isTitleCase(
char32_t ucs4)
noexcept Q_DECL_CONST_FUNCTION
645 {
return ucs4 > 127 && QChar::category(ucs4) == Letter_Titlecase; }
647 friend constexpr bool comparesEqual(
const QChar &lhs,
const QChar &rhs)
noexcept
648 {
return lhs.ucs == rhs.ucs; }
649 friend constexpr Qt::strong_ordering
650 compareThreeWay(
const QChar &lhs,
const QChar &rhs)
noexcept
651 {
return Qt::compareThreeWay(lhs.ucs, rhs.ucs); }
652 Q_DECLARE_STRONGLY_ORDERED_LITERAL_TYPE(QChar)
654 friend constexpr bool comparesEqual(
const QChar &lhs, std::nullptr_t)
noexcept
655 {
return lhs.isNull(); }
656 friend constexpr Qt::strong_ordering
657 compareThreeWay(
const QChar &lhs, std::nullptr_t)
noexcept
658 {
return lhs.isNull() ? Qt::strong_ordering::equivalent : Qt::strong_ordering::greater; }
659 Q_DECLARE_STRONGLY_ORDERED_LITERAL_TYPE(QChar, std::nullptr_t)
662 static bool QT_CHAR_FASTCALL isSpace_helper(
char32_t ucs4)
noexcept Q_DECL_CONST_FUNCTION;
663 static bool QT_CHAR_FASTCALL isLetter_helper(
char32_t ucs4)
noexcept Q_DECL_CONST_FUNCTION;
664 static bool QT_CHAR_FASTCALL isNumber_helper(
char32_t ucs4)
noexcept Q_DECL_CONST_FUNCTION;
665 static bool QT_CHAR_FASTCALL isLetterOrNumber_helper(
char32_t ucs4)
noexcept Q_DECL_CONST_FUNCTION;
669 equal_helper(QChar lhs,
const char *rhs)
noexcept Q_DECL_CONST_FUNCTION;
671 compare_helper(QChar lhs,
const char *rhs)
noexcept Q_DECL_CONST_FUNCTION;
673#if !defined(QT_NO_CAST_FROM_ASCII) && !defined(QT_RESTRICTED_CAST_FROM_ASCII)
675 friend bool comparesEqual(
const QChar &lhs,
const char *rhs)
noexcept
676 {
return equal_helper(lhs, rhs); }
678 friend Qt::strong_ordering compareThreeWay(
const QChar &lhs,
const char *rhs)
noexcept
680 const int res = compare_helper(lhs, rhs);
681 return Qt::compareThreeWay(res, 0);
683 Q_DECLARE_STRONGLY_ORDERED(QChar,
const char *, Q_WEAK_OVERLOAD QT_ASCII_CAST_WARN)