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)); }
36 {
return Qt::compareThreeWay(uchar(lhs.toLatin1()), uchar(rhs)); }
37 Q_DECLARE_STRONGLY_ORDERED_LITERAL_TYPE(
QLatin1Char,
char)
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)) {}
132 constexpr explicit QChar(
char32_t ch)
noexcept;
134 template <
typename Char, if_implicit_conversion_char<Char> =
true>
135 constexpr Q_IMPLICIT QChar(
const Char ch)
noexcept : ucs(
char16_t(ch)) {}
136 template <
typename Char, if_explicit_conversion_char<Char> =
true>
137 constexpr explicit QChar(
const Char ch)
noexcept
138 : ucs((Q_ASSERT(
char32_t(ch) <= 0xffff),
char16_t(ch))) {}
140#ifndef QT_NO_CAST_FROM_ASCII
142#if QT_CORE_REMOVED_SINCE(6
, 9
) || defined(Q_QDOC)
143 QT_ASCII_CAST_WARN
constexpr Q_IMPLICIT QChar(
char c)
noexcept : ucs(uchar(c)) { }
145 template <
typename Char, if_implicit_ascii_warn_char<Char> =
true>
146 QT_ASCII_CAST_WARN
constexpr Q_IMPLICIT QChar(
const Char ch)
noexcept : ucs(uchar(ch)) {}
147#ifndef QT_RESTRICTED_CAST_FROM_ASCII
148#if QT_CORE_REMOVED_SINCE(6
, 9
) || defined(Q_QDOC)
149 QT_ASCII_CAST_WARN
constexpr explicit QChar(uchar c)
noexcept : ucs(c) { }
151 template <
typename Char, if_explicit_ascii_warn_char<Char> =
true>
152 QT_ASCII_CAST_WARN
constexpr explicit QChar(
const Char c)
noexcept : ucs(c) { }
156 static constexpr QChar fromUcs2(
char16_t c)
noexcept {
return QChar{c}; }
157 [[nodiscard]]
static constexpr inline auto fromUcs4(
char32_t c)
noexcept
161 [[nodiscard]]
constexpr qsizetype size()
const noexcept {
return chars[1] ? 2 : 1; }
162 [[nodiscard]]
constexpr const char16_t *data()
const noexcept {
return chars; }
163 [[nodiscard]]
constexpr const char16_t *begin()
const noexcept {
return chars; }
164 [[nodiscard]]
constexpr const char16_t *end()
const noexcept {
return begin() + size(); }
166 return requiresSurrogates(c) ? R{{QChar::highSurrogate(c),
167 QChar::lowSurrogate(c)}} :
168 R{{
char16_t(c), u'\0'}} ;
176 Mark_SpacingCombining,
199 Punctuation_Connector,
203 Punctuation_InitialQuote,
204 Punctuation_FinalQuote,
245 Script_CanadianAboriginal,
307 Script_EgyptianHieroglyphs,
313 Script_ImperialAramaic,
314 Script_OldSouthArabian,
315 Script_InscriptionalParthian,
316 Script_InscriptionalPahlavi,
327 Script_MeroiticCursive,
328 Script_MeroiticHieroglyphs,
335 Script_CaucasianAlbanian,
348 Script_OldNorthArabian,
353 Script_PsalterPahlavi,
361 Script_AnatolianHieroglyphs,
379 Script_ZanabazarSquare,
384 Script_HanifiRohingya,
391 Script_NyiakengPuachueHmong,
397 Script_KhitanSmallScript,
431 DirL, DirR, DirEN, DirES, DirET, DirAN, DirCS, DirB, DirS, DirWS, DirON,
432 DirLRE, DirLRO, DirAL, DirRLE, DirRLO, DirPDF, DirNSM, DirBN,
433 DirLRI, DirRLI, DirFSI, DirPDI
469 Combining_BelowLeftAttached = 200,
470 Combining_BelowAttached = 202,
471 Combining_BelowRightAttached = 204,
472 Combining_LeftAttached = 208,
473 Combining_RightAttached = 210,
474 Combining_AboveLeftAttached = 212,
475 Combining_AboveAttached = 214,
476 Combining_AboveRightAttached = 216,
478 Combining_BelowLeft = 218,
479 Combining_Below = 220,
480 Combining_BelowRight = 222,
481 Combining_Left = 224,
482 Combining_Right = 226,
483 Combining_AboveLeft = 228,
484 Combining_Above = 230,
485 Combining_AboveRight = 232,
487 Combining_DoubleBelow = 233,
488 Combining_DoubleAbove = 234,
489 Combining_IotaSubscript = 240
492 enum UnicodeVersion {
524 Category category()
const noexcept {
return QChar::category(
char32_t(ucs)); }
525 Direction direction()
const noexcept {
return QChar::direction(
char32_t(ucs)); }
526 JoiningType joiningType()
const noexcept {
return QChar::joiningType(
char32_t(ucs)); }
527 unsigned char combiningClass()
const noexcept {
return QChar::combiningClass(
char32_t(ucs)); }
529 QChar mirroredChar()
const noexcept {
return QChar(QChar::mirroredChar(
char32_t(ucs))); }
530 bool hasMirrored()
const noexcept {
return QChar::hasMirrored(
char32_t(ucs)); }
532 QString decomposition()
const;
533 Decomposition decompositionTag()
const noexcept {
return QChar::decompositionTag(
char32_t(ucs)); }
535 int digitValue()
const noexcept {
return QChar::digitValue(
char32_t(ucs)); }
536 QChar toLower()
const noexcept {
return QChar(QChar::toLower(
char32_t(ucs))); }
537 QChar toUpper()
const noexcept {
return QChar(QChar::toUpper(
char32_t(ucs))); }
538 QChar toTitleCase()
const noexcept {
return QChar(QChar::toTitleCase(
char32_t(ucs))); }
539 QChar toCaseFolded()
const noexcept {
return QChar(QChar::toCaseFolded(
char32_t(ucs))); }
541 Script script()
const noexcept {
return QChar::script(
char32_t(ucs)); }
543 UnicodeVersion unicodeVersion()
const noexcept {
return QChar::unicodeVersion(
char32_t(ucs)); }
545 constexpr inline char toLatin1()
const noexcept {
return ucs > 0xff ?
'\0' :
char(ucs); }
546 constexpr inline char16_t unicode()
const noexcept {
return ucs; }
547 constexpr inline char16_t &unicode()
noexcept {
return ucs; }
549 static constexpr QChar fromLatin1(
char c)
noexcept {
return QLatin1Char(c); }
551 constexpr inline bool isNull()
const noexcept {
return ucs == 0; }
553 bool isPrint()
const noexcept {
return QChar::isPrint(
char32_t(ucs)); }
554 constexpr bool isSpace()
const noexcept {
return QChar::isSpace(
char32_t(ucs)); }
555 bool isMark()
const noexcept {
return QChar::isMark(
char32_t(ucs)); }
556 bool isPunct()
const noexcept {
return QChar::isPunct(
char32_t(ucs)); }
557 bool isSymbol()
const noexcept {
return QChar::isSymbol(
char32_t(ucs)); }
558 constexpr bool isLetter()
const noexcept {
return QChar::isLetter(
char32_t(ucs)); }
559 constexpr bool isNumber()
const noexcept {
return QChar::isNumber(
char32_t(ucs)); }
560 constexpr bool isLetterOrNumber()
const noexcept {
return QChar::isLetterOrNumber(
char32_t(ucs)); }
561 constexpr bool isDigit()
const noexcept {
return QChar::isDigit(
char32_t(ucs)); }
562 constexpr bool isLower()
const noexcept {
return QChar::isLower(
char32_t(ucs)); }
563 constexpr bool isUpper()
const noexcept {
return QChar::isUpper(
char32_t(ucs)); }
564 constexpr bool isTitleCase()
const noexcept {
return QChar::isTitleCase(
char32_t(ucs)); }
566 constexpr bool isNonCharacter()
const noexcept {
return QChar::isNonCharacter(
char32_t(ucs)); }
567 constexpr bool isHighSurrogate()
const noexcept {
return QChar::isHighSurrogate(
char32_t(ucs)); }
568 constexpr bool isLowSurrogate()
const noexcept {
return QChar::isLowSurrogate(
char32_t(ucs)); }
569 constexpr bool isSurrogate()
const noexcept {
return QChar::isSurrogate(
char32_t(ucs)); }
571 constexpr inline uchar cell()
const noexcept {
return uchar(ucs & 0xff); }
572 constexpr inline uchar row()
const noexcept {
return uchar((ucs>>8)&0xff); }
573 constexpr inline void setCell(uchar acell)
noexcept { ucs =
char16_t((ucs & 0xff00) + acell); }
574 constexpr inline void setRow(uchar arow)
noexcept { ucs =
char16_t((
char16_t(arow)<<8) + (ucs&0xff)); }
576 static constexpr inline bool isNonCharacter(
char32_t ucs4)
noexcept
578 return ucs4 >= 0xfdd0 && (ucs4 <= 0xfdef || (ucs4 & 0xfffe) == 0xfffe);
580 static constexpr inline bool isHighSurrogate(
char32_t ucs4)
noexcept
582 return (ucs4 & 0xfffffc00) == 0xd800;
584 static constexpr inline bool isLowSurrogate(
char32_t ucs4)
noexcept
586 return (ucs4 & 0xfffffc00) == 0xdc00;
588 static constexpr inline bool isSurrogate(
char32_t ucs4)
noexcept
590 return (ucs4 - 0xd800u < 2048u);
592 static constexpr inline bool requiresSurrogates(
char32_t ucs4)
noexcept
594 return (ucs4 >= 0x10000);
596 static constexpr inline char32_t surrogateToUcs4(
char16_t high,
char16_t low)
noexcept
600 return (
char32_t(high)<<10) + low - 0x35fdc00;
602 static constexpr inline char32_t surrogateToUcs4(QChar high, QChar low)
noexcept
604 return surrogateToUcs4(high.ucs, low.ucs);
606 static constexpr inline char16_t highSurrogate(
char32_t ucs4)
noexcept
608 return char16_t((ucs4>>10) + 0xd7c0);
610 static constexpr inline char16_t lowSurrogate(
char32_t ucs4)
noexcept
612 return char16_t(ucs4%0x400 + 0xdc00);
615 Q_DECL_CONST_FUNCTION
static Category
QT_CHAR_FASTCALL category(
char32_t ucs4)
noexcept;
616 Q_DECL_CONST_FUNCTION
static Direction
QT_CHAR_FASTCALL direction(
char32_t ucs4)
noexcept;
617 Q_DECL_CONST_FUNCTION
static JoiningType
QT_CHAR_FASTCALL joiningType(
char32_t ucs4)
noexcept;
618 Q_DECL_CONST_FUNCTION
static unsigned char QT_CHAR_FASTCALL combiningClass(
char32_t ucs4)
noexcept;
620 Q_DECL_CONST_FUNCTION
static char32_t QT_CHAR_FASTCALL mirroredChar(
char32_t ucs4)
noexcept;
621 Q_DECL_CONST_FUNCTION
static bool QT_CHAR_FASTCALL hasMirrored(
char32_t ucs4)
noexcept;
624 Q_DECL_CONST_FUNCTION
static Decomposition
QT_CHAR_FASTCALL decompositionTag(
char32_t ucs4)
noexcept;
626 Q_DECL_CONST_FUNCTION
static int QT_CHAR_FASTCALL digitValue(
char32_t ucs4)
noexcept;
627 Q_DECL_CONST_FUNCTION
static char32_t QT_CHAR_FASTCALL toLower(
char32_t ucs4)
noexcept;
628 Q_DECL_CONST_FUNCTION
static char32_t QT_CHAR_FASTCALL toUpper(
char32_t ucs4)
noexcept;
629 Q_DECL_CONST_FUNCTION
static char32_t QT_CHAR_FASTCALL toTitleCase(
char32_t ucs4)
noexcept;
630 Q_DECL_CONST_FUNCTION
static char32_t QT_CHAR_FASTCALL toCaseFolded(
char32_t ucs4)
noexcept;
632 Q_DECL_CONST_FUNCTION
static Script
QT_CHAR_FASTCALL script(
char32_t ucs4)
noexcept;
634 Q_DECL_CONST_FUNCTION
static UnicodeVersion
QT_CHAR_FASTCALL unicodeVersion(
char32_t ucs4)
noexcept;
636 Q_DECL_CONST_FUNCTION
static UnicodeVersion
QT_CHAR_FASTCALL currentUnicodeVersion()
noexcept;
638 Q_DECL_CONST_FUNCTION
static bool QT_CHAR_FASTCALL isPrint(
char32_t ucs4)
noexcept;
639 Q_DECL_CONST_FUNCTION
static constexpr inline bool isSpace(
char32_t ucs4)
noexcept
642 return ucs4 == 0x20 || (ucs4 <= 0x0d && ucs4 >= 0x09)
643 || (ucs4 > 127 && (ucs4 == 0x85 || ucs4 == 0xa0 || QChar::isSpace_helper(ucs4)));
645 Q_DECL_CONST_FUNCTION
static bool QT_CHAR_FASTCALL isMark(
char32_t ucs4)
noexcept;
646 Q_DECL_CONST_FUNCTION
static bool QT_CHAR_FASTCALL isPunct(
char32_t ucs4)
noexcept;
647 Q_DECL_CONST_FUNCTION
static bool QT_CHAR_FASTCALL isSymbol(
char32_t ucs4)
noexcept;
648 Q_DECL_CONST_FUNCTION
static constexpr inline bool isLetter(
char32_t ucs4)
noexcept
650 return (ucs4 >=
'A' && ucs4 <=
'z' && (ucs4 >=
'a' || ucs4 <=
'Z'))
651 || (ucs4 > 127 && QChar::isLetter_helper(ucs4));
653 Q_DECL_CONST_FUNCTION
static constexpr inline bool isNumber(
char32_t ucs4)
noexcept
654 {
return (ucs4 <=
'9' && ucs4 >=
'0') || (ucs4 > 127 && QChar::isNumber_helper(ucs4)); }
655 Q_DECL_CONST_FUNCTION
static constexpr inline bool isLetterOrNumber(
char32_t ucs4)
noexcept
657 return (ucs4 >=
'A' && ucs4 <=
'z' && (ucs4 >=
'a' || ucs4 <=
'Z'))
658 || (ucs4 >=
'0' && ucs4 <=
'9')
659 || (ucs4 > 127 && QChar::isLetterOrNumber_helper(ucs4));
661 Q_DECL_CONST_FUNCTION
static constexpr inline bool isDigit(
char32_t ucs4)
noexcept
662 {
return (ucs4 <=
'9' && ucs4 >=
'0') || (ucs4 > 127 && QChar::category(ucs4) == Number_DecimalDigit); }
663 Q_DECL_CONST_FUNCTION
static constexpr inline bool isLower(
char32_t ucs4)
noexcept
664 {
return (ucs4 <=
'z' && ucs4 >=
'a') || (ucs4 > 127 && QChar::category(ucs4) == Letter_Lowercase); }
665 Q_DECL_CONST_FUNCTION
static constexpr inline bool isUpper(
char32_t ucs4)
noexcept
666 {
return (ucs4 <=
'Z' && ucs4 >=
'A') || (ucs4 > 127 && QChar::category(ucs4) == Letter_Uppercase); }
667 Q_DECL_CONST_FUNCTION
static constexpr inline bool isTitleCase(
char32_t ucs4)
noexcept
668 {
return ucs4 > 127 && QChar::category(ucs4) == Letter_Titlecase; }
670 friend constexpr bool comparesEqual(
const QChar &lhs,
const QChar &rhs)
noexcept
671 {
return lhs.ucs == rhs.ucs; }
672 friend constexpr Qt::strong_ordering
673 compareThreeWay(
const QChar &lhs,
const QChar &rhs)
noexcept
674 {
return Qt::compareThreeWay(lhs.ucs, rhs.ucs); }
675 Q_DECLARE_STRONGLY_ORDERED_LITERAL_TYPE(QChar)
677 friend constexpr bool comparesEqual(
const QChar &lhs, std::nullptr_t)
noexcept
678 {
return lhs.isNull(); }
679 friend constexpr Qt::strong_ordering
680 compareThreeWay(
const QChar &lhs, std::nullptr_t)
noexcept
681 {
return lhs.isNull() ? Qt::strong_ordering::equivalent : Qt::strong_ordering::greater; }
682 Q_DECLARE_STRONGLY_ORDERED_LITERAL_TYPE(QChar, std::nullptr_t)
685 Q_DECL_CONST_FUNCTION
static bool QT_CHAR_FASTCALL isSpace_helper(
char32_t ucs4)
noexcept;
686 Q_DECL_CONST_FUNCTION
static bool QT_CHAR_FASTCALL isLetter_helper(
char32_t ucs4)
noexcept;
687 Q_DECL_CONST_FUNCTION
static bool QT_CHAR_FASTCALL isNumber_helper(
char32_t ucs4)
noexcept;
688 Q_DECL_CONST_FUNCTION
static bool QT_CHAR_FASTCALL isLetterOrNumber_helper(
char32_t ucs4)
noexcept;
692 Q_DECL_CONST_FUNCTION equal_helper(QChar lhs,
const char *rhs)
noexcept;
694 Q_DECL_CONST_FUNCTION compare_helper(QChar lhs,
const char *rhs)
noexcept;
696#if !defined(QT_NO_CAST_FROM_ASCII) && !defined(QT_RESTRICTED_CAST_FROM_ASCII)
698 friend bool comparesEqual(
const QChar &lhs,
const char *rhs)
noexcept
699 {
return equal_helper(lhs, rhs); }
701 friend Qt::strong_ordering compareThreeWay(
const QChar &lhs,
const char *rhs)
noexcept
703 const int res = compare_helper(lhs, rhs);
704 return Qt::compareThreeWay(res, 0);
706 Q_DECLARE_STRONGLY_ORDERED(QChar,
const char *, Q_WEAK_OVERLOAD QT_ASCII_CAST_WARN)