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 static constexpr inline auto fromUcs4(
char32_t c)
noexcept;
161 Mark_SpacingCombining,
184 Punctuation_Connector,
188 Punctuation_InitialQuote,
189 Punctuation_FinalQuote,
230 Script_CanadianAboriginal,
292 Script_EgyptianHieroglyphs,
298 Script_ImperialAramaic,
299 Script_OldSouthArabian,
300 Script_InscriptionalParthian,
301 Script_InscriptionalPahlavi,
312 Script_MeroiticCursive,
313 Script_MeroiticHieroglyphs,
320 Script_CaucasianAlbanian,
333 Script_OldNorthArabian,
338 Script_PsalterPahlavi,
346 Script_AnatolianHieroglyphs,
364 Script_ZanabazarSquare,
369 Script_HanifiRohingya,
376 Script_NyiakengPuachueHmong,
382 Script_KhitanSmallScript,
410 DirL, DirR, DirEN, DirES, DirET, DirAN, DirCS, DirB, DirS, DirWS, DirON,
411 DirLRE, DirLRO, DirAL, DirRLE, DirRLO, DirPDF, DirNSM, DirBN,
412 DirLRI, DirRLI, DirFSI, DirPDI
448 Combining_BelowLeftAttached = 200,
449 Combining_BelowAttached = 202,
450 Combining_BelowRightAttached = 204,
451 Combining_LeftAttached = 208,
452 Combining_RightAttached = 210,
453 Combining_AboveLeftAttached = 212,
454 Combining_AboveAttached = 214,
455 Combining_AboveRightAttached = 216,
457 Combining_BelowLeft = 218,
458 Combining_Below = 220,
459 Combining_BelowRight = 222,
460 Combining_Left = 224,
461 Combining_Right = 226,
462 Combining_AboveLeft = 228,
463 Combining_Above = 230,
464 Combining_AboveRight = 232,
466 Combining_DoubleBelow = 233,
467 Combining_DoubleAbove = 234,
468 Combining_IotaSubscript = 240
471 enum UnicodeVersion {
502 inline Category category()
const noexcept {
return QChar::category(ucs); }
503 inline Direction direction()
const noexcept {
return QChar::direction(ucs); }
504 inline JoiningType joiningType()
const noexcept {
return QChar::joiningType(ucs); }
505 inline unsigned char combiningClass()
const noexcept {
return QChar::combiningClass(ucs); }
507 inline QChar mirroredChar()
const noexcept {
return QChar(QChar::mirroredChar(ucs)); }
508 inline bool hasMirrored()
const noexcept {
return QChar::hasMirrored(ucs); }
510 QString decomposition()
const;
511 inline Decomposition decompositionTag()
const noexcept {
return QChar::decompositionTag(ucs); }
513 inline int digitValue()
const noexcept {
return QChar::digitValue(ucs); }
514 inline QChar toLower()
const noexcept {
return QChar(QChar::toLower(ucs)); }
515 inline QChar toUpper()
const noexcept {
return QChar(QChar::toUpper(ucs)); }
516 inline QChar toTitleCase()
const noexcept {
return QChar(QChar::toTitleCase(ucs)); }
517 inline QChar toCaseFolded()
const noexcept {
return QChar(QChar::toCaseFolded(ucs)); }
519 inline Script script()
const noexcept {
return QChar::script(ucs); }
521 inline UnicodeVersion unicodeVersion()
const noexcept {
return QChar::unicodeVersion(ucs); }
523 constexpr inline char toLatin1()
const noexcept {
return ucs > 0xff ?
'\0' :
char(ucs); }
524 constexpr inline char16_t unicode()
const noexcept {
return ucs; }
525 constexpr inline char16_t &unicode()
noexcept {
return ucs; }
527 static constexpr QChar fromLatin1(
char c)
noexcept {
return QLatin1Char(c); }
529 constexpr inline bool isNull()
const noexcept {
return ucs == 0; }
531 inline bool isPrint()
const noexcept {
return QChar::isPrint(ucs); }
532 constexpr inline bool isSpace()
const noexcept {
return QChar::isSpace(ucs); }
533 inline bool isMark()
const noexcept {
return QChar::isMark(ucs); }
534 inline bool isPunct()
const noexcept {
return QChar::isPunct(ucs); }
535 inline bool isSymbol()
const noexcept {
return QChar::isSymbol(ucs); }
536 constexpr inline bool isLetter()
const noexcept {
return QChar::isLetter(ucs); }
537 constexpr inline bool isNumber()
const noexcept {
return QChar::isNumber(ucs); }
538 constexpr inline bool isLetterOrNumber()
const noexcept {
return QChar::isLetterOrNumber(ucs); }
539 constexpr inline bool isDigit()
const noexcept {
return QChar::isDigit(ucs); }
540 constexpr inline bool isLower()
const noexcept {
return QChar::isLower(ucs); }
541 constexpr inline bool isUpper()
const noexcept {
return QChar::isUpper(ucs); }
542 constexpr inline bool isTitleCase()
const noexcept {
return QChar::isTitleCase(ucs); }
544 constexpr inline bool isNonCharacter()
const noexcept {
return QChar::isNonCharacter(ucs); }
545 constexpr inline bool isHighSurrogate()
const noexcept {
return QChar::isHighSurrogate(ucs); }
546 constexpr inline bool isLowSurrogate()
const noexcept {
return QChar::isLowSurrogate(ucs); }
547 constexpr inline bool isSurrogate()
const noexcept {
return QChar::isSurrogate(ucs); }
549 constexpr inline uchar cell()
const noexcept {
return uchar(ucs & 0xff); }
550 constexpr inline uchar row()
const noexcept {
return uchar((ucs>>8)&0xff); }
551 constexpr inline void setCell(uchar acell)
noexcept { ucs =
char16_t((ucs & 0xff00) + acell); }
552 constexpr inline void setRow(uchar arow)
noexcept { ucs =
char16_t((
char16_t(arow)<<8) + (ucs&0xff)); }
554 static constexpr inline bool isNonCharacter(
char32_t ucs4)
noexcept
556 return ucs4 >= 0xfdd0 && (ucs4 <= 0xfdef || (ucs4 & 0xfffe) == 0xfffe);
558 static constexpr inline bool isHighSurrogate(
char32_t ucs4)
noexcept
560 return (ucs4 & 0xfffffc00) == 0xd800;
562 static constexpr inline bool isLowSurrogate(
char32_t ucs4)
noexcept
564 return (ucs4 & 0xfffffc00) == 0xdc00;
566 static constexpr inline bool isSurrogate(
char32_t ucs4)
noexcept
568 return (ucs4 - 0xd800u < 2048u);
570 static constexpr inline bool requiresSurrogates(
char32_t ucs4)
noexcept
572 return (ucs4 >= 0x10000);
574 static constexpr inline char32_t surrogateToUcs4(
char16_t high,
char16_t low)
noexcept
578 return (
char32_t(high)<<10) + low - 0x35fdc00;
580 static constexpr inline char32_t surrogateToUcs4(QChar high, QChar low)
noexcept
582 return surrogateToUcs4(high.ucs, low.ucs);
584 static constexpr inline char16_t highSurrogate(
char32_t ucs4)
noexcept
586 return char16_t((ucs4>>10) + 0xd7c0);
588 static constexpr inline char16_t lowSurrogate(
char32_t ucs4)
noexcept
590 return char16_t(ucs4%0x400 + 0xdc00);
593 Q_DECL_CONST_FUNCTION
static Category
QT_CHAR_FASTCALL category(
char32_t ucs4)
noexcept;
594 Q_DECL_CONST_FUNCTION
static Direction
QT_CHAR_FASTCALL direction(
char32_t ucs4)
noexcept;
595 Q_DECL_CONST_FUNCTION
static JoiningType
QT_CHAR_FASTCALL joiningType(
char32_t ucs4)
noexcept;
596 Q_DECL_CONST_FUNCTION
static unsigned char QT_CHAR_FASTCALL combiningClass(
char32_t ucs4)
noexcept;
598 Q_DECL_CONST_FUNCTION
static char32_t QT_CHAR_FASTCALL mirroredChar(
char32_t ucs4)
noexcept;
599 Q_DECL_CONST_FUNCTION
static bool QT_CHAR_FASTCALL hasMirrored(
char32_t ucs4)
noexcept;
602 Q_DECL_CONST_FUNCTION
static Decomposition
QT_CHAR_FASTCALL decompositionTag(
char32_t ucs4)
noexcept;
604 Q_DECL_CONST_FUNCTION
static int QT_CHAR_FASTCALL digitValue(
char32_t ucs4)
noexcept;
605 Q_DECL_CONST_FUNCTION
static char32_t QT_CHAR_FASTCALL toLower(
char32_t ucs4)
noexcept;
606 Q_DECL_CONST_FUNCTION
static char32_t QT_CHAR_FASTCALL toUpper(
char32_t ucs4)
noexcept;
607 Q_DECL_CONST_FUNCTION
static char32_t QT_CHAR_FASTCALL toTitleCase(
char32_t ucs4)
noexcept;
608 Q_DECL_CONST_FUNCTION
static char32_t QT_CHAR_FASTCALL toCaseFolded(
char32_t ucs4)
noexcept;
610 Q_DECL_CONST_FUNCTION
static Script
QT_CHAR_FASTCALL script(
char32_t ucs4)
noexcept;
612 Q_DECL_CONST_FUNCTION
static UnicodeVersion
QT_CHAR_FASTCALL unicodeVersion(
char32_t ucs4)
noexcept;
614 Q_DECL_CONST_FUNCTION
static UnicodeVersion
QT_CHAR_FASTCALL currentUnicodeVersion()
noexcept;
616 Q_DECL_CONST_FUNCTION
static bool QT_CHAR_FASTCALL isPrint(
char32_t ucs4)
noexcept;
617 Q_DECL_CONST_FUNCTION
static constexpr inline bool isSpace(
char32_t ucs4)
noexcept
620 return ucs4 == 0x20 || (ucs4 <= 0x0d && ucs4 >= 0x09)
621 || (ucs4 > 127 && (ucs4 == 0x85 || ucs4 == 0xa0 || QChar::isSpace_helper(ucs4)));
623 Q_DECL_CONST_FUNCTION
static bool QT_CHAR_FASTCALL isMark(
char32_t ucs4)
noexcept;
624 Q_DECL_CONST_FUNCTION
static bool QT_CHAR_FASTCALL isPunct(
char32_t ucs4)
noexcept;
625 Q_DECL_CONST_FUNCTION
static bool QT_CHAR_FASTCALL isSymbol(
char32_t ucs4)
noexcept;
626 Q_DECL_CONST_FUNCTION
static constexpr inline bool isLetter(
char32_t ucs4)
noexcept
628 return (ucs4 >=
'A' && ucs4 <=
'z' && (ucs4 >=
'a' || ucs4 <=
'Z'))
629 || (ucs4 > 127 && QChar::isLetter_helper(ucs4));
631 Q_DECL_CONST_FUNCTION
static constexpr inline bool isNumber(
char32_t ucs4)
noexcept
632 {
return (ucs4 <=
'9' && ucs4 >=
'0') || (ucs4 > 127 && QChar::isNumber_helper(ucs4)); }
633 Q_DECL_CONST_FUNCTION
static constexpr inline bool isLetterOrNumber(
char32_t ucs4)
noexcept
635 return (ucs4 >=
'A' && ucs4 <=
'z' && (ucs4 >=
'a' || ucs4 <=
'Z'))
636 || (ucs4 >=
'0' && ucs4 <=
'9')
637 || (ucs4 > 127 && QChar::isLetterOrNumber_helper(ucs4));
639 Q_DECL_CONST_FUNCTION
static constexpr inline bool isDigit(
char32_t ucs4)
noexcept
640 {
return (ucs4 <=
'9' && ucs4 >=
'0') || (ucs4 > 127 && QChar::category(ucs4) == Number_DecimalDigit); }
641 Q_DECL_CONST_FUNCTION
static constexpr inline bool isLower(
char32_t ucs4)
noexcept
642 {
return (ucs4 <=
'z' && ucs4 >=
'a') || (ucs4 > 127 && QChar::category(ucs4) == Letter_Lowercase); }
643 Q_DECL_CONST_FUNCTION
static constexpr inline bool isUpper(
char32_t ucs4)
noexcept
644 {
return (ucs4 <=
'Z' && ucs4 >=
'A') || (ucs4 > 127 && QChar::category(ucs4) == Letter_Uppercase); }
645 Q_DECL_CONST_FUNCTION
static constexpr inline bool isTitleCase(
char32_t ucs4)
noexcept
646 {
return ucs4 > 127 && QChar::category(ucs4) == Letter_Titlecase; }
648 friend constexpr bool comparesEqual(
const QChar &lhs,
const QChar &rhs)
noexcept
649 {
return lhs.ucs == rhs.ucs; }
650 friend constexpr Qt::strong_ordering
651 compareThreeWay(
const QChar &lhs,
const QChar &rhs)
noexcept
652 {
return Qt::compareThreeWay(lhs.ucs, rhs.ucs); }
653 Q_DECLARE_STRONGLY_ORDERED_LITERAL_TYPE(QChar)
655 friend constexpr bool comparesEqual(
const QChar &lhs, std::nullptr_t)
noexcept
656 {
return lhs.isNull(); }
657 friend constexpr Qt::strong_ordering
658 compareThreeWay(
const QChar &lhs, std::nullptr_t)
noexcept
659 {
return lhs.isNull() ? Qt::strong_ordering::equivalent : Qt::strong_ordering::greater; }
660 Q_DECLARE_STRONGLY_ORDERED_LITERAL_TYPE(QChar, std::nullptr_t)
663 Q_DECL_CONST_FUNCTION
static bool QT_CHAR_FASTCALL isSpace_helper(
char32_t ucs4)
noexcept;
664 Q_DECL_CONST_FUNCTION
static bool QT_CHAR_FASTCALL isLetter_helper(
char32_t ucs4)
noexcept;
665 Q_DECL_CONST_FUNCTION
static bool QT_CHAR_FASTCALL isNumber_helper(
char32_t ucs4)
noexcept;
666 Q_DECL_CONST_FUNCTION
static bool QT_CHAR_FASTCALL isLetterOrNumber_helper(
char32_t ucs4)
noexcept;
670 Q_DECL_CONST_FUNCTION equal_helper(QChar lhs,
const char *rhs)
noexcept;
672 Q_DECL_CONST_FUNCTION compare_helper(QChar lhs,
const char *rhs)
noexcept;
674#if !defined(QT_NO_CAST_FROM_ASCII) && !defined(QT_RESTRICTED_CAST_FROM_ASCII)
676 friend bool comparesEqual(
const QChar &lhs,
const char *rhs)
noexcept
677 {
return equal_helper(lhs, rhs); }
679 friend Qt::strong_ordering compareThreeWay(
const QChar &lhs,
const char *rhs)
noexcept
681 const int res = compare_helper(lhs, rhs);
682 return Qt::compareThreeWay(res, 0);
684 Q_DECLARE_STRONGLY_ORDERED(QChar,
const char *, Q_WEAK_OVERLOAD QT_ASCII_CAST_WARN)