Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-11-02 09:49:46

0001 // Copyright (C) 2020 The Qt Company Ltd.
0002 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
0003 
0004 #ifndef QCHAR_H
0005 #define QCHAR_H
0006 
0007 #include <QtCore/qglobal.h>
0008 #include <QtCore/qcompare.h>
0009 
0010 #include <functional> // for std::hash
0011 
0012 QT_BEGIN_NAMESPACE
0013 
0014 class QDataStream;
0015 class QString;
0016 
0017 struct QLatin1Char
0018 {
0019 public:
0020     constexpr inline explicit QLatin1Char(char c) noexcept : ch(c) {}
0021     constexpr inline char toLatin1() const noexcept { return ch; }
0022     constexpr inline char16_t unicode() const noexcept { return char16_t(uchar(ch)); }
0023 
0024     friend constexpr bool
0025     comparesEqual(const QLatin1Char &lhs, const QLatin1Char &rhs) noexcept
0026     { return lhs.ch == rhs.ch; }
0027     friend constexpr Qt::strong_ordering
0028     compareThreeWay(const QLatin1Char &lhs, const QLatin1Char &rhs) noexcept
0029     { return Qt::compareThreeWay(uchar(lhs.ch), uchar(rhs.ch)); }
0030     Q_DECLARE_STRONGLY_ORDERED_LITERAL_TYPE(QLatin1Char)
0031 
0032     friend constexpr bool comparesEqual(const QLatin1Char &lhs, char rhs) noexcept
0033     { return lhs.toLatin1() == rhs; }
0034     friend constexpr Qt::strong_ordering
0035     compareThreeWay(const QLatin1Char &lhs, char rhs) noexcept
0036     { return Qt::compareThreeWay(uchar(lhs.toLatin1()), uchar(rhs)); }
0037     Q_DECLARE_STRONGLY_ORDERED_LITERAL_TYPE(QLatin1Char, char)
0038 
0039 private:
0040     friend class QChar;
0041     // this is for QChar's ctor only:
0042     explicit constexpr operator char16_t() const noexcept { return unicode(); }
0043 
0044     char ch;
0045 };
0046 
0047 #define QT_CHAR_FASTCALL QT7_ONLY(Q_CORE_EXPORT) QT_FASTCALL
0048 class QT6_ONLY(Q_CORE_EXPORT) QChar {
0049 public:
0050     enum SpecialCharacter {
0051         Null = 0x0000,
0052         Tabulation = 0x0009,
0053         LineFeed = 0x000a,
0054         FormFeed = 0x000c,
0055         CarriageReturn = 0x000d,
0056         Space = 0x0020,
0057         Nbsp = 0x00a0,
0058         SoftHyphen = 0x00ad,
0059         ReplacementCharacter = 0xfffd,
0060         ObjectReplacementCharacter = 0xfffc,
0061         ByteOrderMark = 0xfeff,
0062         ByteOrderSwapped = 0xfffe,
0063         ParagraphSeparator = 0x2029,
0064         LineSeparator = 0x2028,
0065         VisualTabCharacter = 0x2192,
0066         LastValidCodePoint = 0x10ffff
0067     };
0068 
0069 #ifdef QT_IMPLICIT_QCHAR_CONSTRUCTION
0070 #error This macro has been removed in Qt 6.8.
0071 #endif
0072 private:
0073     using is_wide_wchar_t = std::bool_constant<(sizeof(wchar_t) > 2)>;
0074     template <typename Char>
0075     using is_implicit_conversion_char = std::disjunction<
0076             std::is_same<Char, ushort>,
0077             std::is_same<Char, short>,
0078             std::is_same<Char, SpecialCharacter>,
0079             std::is_same<Char, QLatin1Char>,
0080             std::conjunction<std::is_same<Char, wchar_t>, std::negation<is_wide_wchar_t>>,
0081             std::is_same<Char, char16_t>
0082         >;
0083     template <typename Char>
0084     using is_explicit_conversion_char = std::disjunction<
0085             std::is_same<Char, char32_t>, // implicit conversion to uint(?) before 6.8
0086             std::conjunction<std::is_same<Char, wchar_t>, is_wide_wchar_t>,
0087             std::is_same<Char, int>,
0088             std::is_same<Char, uint>
0089         >;
0090     template <typename Char>
0091     using is_conversion_char = std::disjunction<
0092             is_implicit_conversion_char<Char>,
0093             is_explicit_conversion_char<Char>
0094         >;
0095     template <typename Char>
0096     using is_implicit_ascii_warn_char = std::is_same<Char, char>;
0097     template <typename Char>
0098     using is_explicit_ascii_warn_char = std::is_same<Char, uchar>;
0099     template <typename Char>
0100     using if_compatible_char = std::enable_if_t<is_conversion_char<Char>::value, bool>;
0101     template <typename Char>
0102     using if_implicit_conversion_char = std::enable_if_t<is_implicit_conversion_char<Char>::value, bool>;
0103     template <typename Char>
0104     using if_explicit_conversion_char = std::enable_if_t<is_explicit_conversion_char<Char>::value, bool>;
0105     template <typename Char>
0106     using if_implicit_ascii_warn_char = std::enable_if_t<is_implicit_ascii_warn_char<Char>::value, bool>;
0107     template <typename Char>
0108     using if_explicit_ascii_warn_char = std::enable_if_t<is_explicit_ascii_warn_char<Char>::value, bool>;
0109     template <typename Char>
0110     [[maybe_unused]] static constexpr bool is_explicit_char_v = std::disjunction_v<
0111             is_explicit_conversion_char<Char>,
0112             is_explicit_ascii_warn_char<Char>
0113         >;
0114 public:
0115     constexpr Q_IMPLICIT QChar() noexcept : ucs(0) {}
0116 #if QT_CORE_REMOVED_SINCE(6, 9) || defined(Q_QDOC)
0117     constexpr Q_IMPLICIT QChar(ushort rc) noexcept : ucs(rc) {}
0118 #endif
0119     constexpr explicit QChar(uchar c, uchar r) noexcept : ucs(char16_t((r << 8) | c)) {}
0120 #if QT_CORE_REMOVED_SINCE(6, 9) || defined(Q_QDOC)
0121     constexpr Q_IMPLICIT QChar(short rc) noexcept : ucs(char16_t(rc)) {}
0122     constexpr explicit QChar(uint rc) noexcept : ucs((Q_ASSERT(rc <= 0xffff), char16_t(rc))) {}
0123     constexpr explicit QChar(int rc) noexcept : QChar(uint(rc)) {}
0124     constexpr Q_IMPLICIT QChar(SpecialCharacter s) noexcept : ucs(char16_t(s)) {}
0125     constexpr Q_IMPLICIT QChar(QLatin1Char ch) noexcept : ucs(ch.unicode()) {}
0126     constexpr Q_IMPLICIT QChar(char16_t ch) noexcept : ucs(ch) {}
0127 #if defined(Q_OS_WIN) || defined(Q_QDOC)
0128     constexpr Q_IMPLICIT QChar(wchar_t ch) noexcept : ucs(char16_t(ch)) {}
0129 #endif
0130 #endif // QT_CORE_REMOVED_SINCE(6, 9)
0131     template <typename Char, if_implicit_conversion_char<Char> = true>
0132     constexpr Q_IMPLICIT QChar(const Char ch) noexcept : ucs(char16_t(ch)) {}
0133     template <typename Char, if_explicit_conversion_char<Char> = true>
0134     constexpr explicit QChar(const Char ch) noexcept
0135         : ucs((Q_ASSERT(char32_t(ch) <= 0xffff), char16_t(ch))) {}
0136 
0137 #ifndef QT_NO_CAST_FROM_ASCII
0138     // Always implicit -- allow for 'x' => QChar conversions
0139 #if QT_CORE_REMOVED_SINCE(6, 9) || defined(Q_QDOC)
0140     QT_ASCII_CAST_WARN constexpr Q_IMPLICIT QChar(char c) noexcept : ucs(uchar(c)) { }
0141 #endif
0142     template <typename Char, if_implicit_ascii_warn_char<Char> = true>
0143     QT_ASCII_CAST_WARN constexpr Q_IMPLICIT QChar(const Char ch) noexcept : ucs(uchar(ch)) {}
0144 #ifndef QT_RESTRICTED_CAST_FROM_ASCII
0145 #if QT_CORE_REMOVED_SINCE(6, 9) || defined(Q_QDOC)
0146     QT_ASCII_CAST_WARN constexpr explicit QChar(uchar c) noexcept : ucs(c) { }
0147 #endif
0148     template <typename Char, if_explicit_ascii_warn_char<Char> = true>
0149     QT_ASCII_CAST_WARN constexpr explicit QChar(const Char c) noexcept : ucs(c) { }
0150 #endif
0151 #endif
0152 
0153     static constexpr QChar fromUcs2(char16_t c) noexcept { return QChar{c}; }
0154     static constexpr inline auto fromUcs4(char32_t c) noexcept;
0155 
0156     // Unicode information
0157 
0158     enum Category
0159     {
0160         Mark_NonSpacing,          //   Mn
0161         Mark_SpacingCombining,    //   Mc
0162         Mark_Enclosing,           //   Me
0163 
0164         Number_DecimalDigit,      //   Nd
0165         Number_Letter,            //   Nl
0166         Number_Other,             //   No
0167 
0168         Separator_Space,          //   Zs
0169         Separator_Line,           //   Zl
0170         Separator_Paragraph,      //   Zp
0171 
0172         Other_Control,            //   Cc
0173         Other_Format,             //   Cf
0174         Other_Surrogate,          //   Cs
0175         Other_PrivateUse,         //   Co
0176         Other_NotAssigned,        //   Cn
0177 
0178         Letter_Uppercase,         //   Lu
0179         Letter_Lowercase,         //   Ll
0180         Letter_Titlecase,         //   Lt
0181         Letter_Modifier,          //   Lm
0182         Letter_Other,             //   Lo
0183 
0184         Punctuation_Connector,    //   Pc
0185         Punctuation_Dash,         //   Pd
0186         Punctuation_Open,         //   Ps
0187         Punctuation_Close,        //   Pe
0188         Punctuation_InitialQuote, //   Pi
0189         Punctuation_FinalQuote,   //   Pf
0190         Punctuation_Other,        //   Po
0191 
0192         Symbol_Math,              //   Sm
0193         Symbol_Currency,          //   Sc
0194         Symbol_Modifier,          //   Sk
0195         Symbol_Other              //   So
0196     };
0197 
0198     enum Script
0199     {
0200         Script_Unknown,
0201         Script_Inherited,
0202         Script_Common,
0203 
0204         Script_Latin,
0205         Script_Greek,
0206         Script_Cyrillic,
0207         Script_Armenian,
0208         Script_Hebrew,
0209         Script_Arabic,
0210         Script_Syriac,
0211         Script_Thaana,
0212         Script_Devanagari,
0213         Script_Bengali,
0214         Script_Gurmukhi,
0215         Script_Gujarati,
0216         Script_Oriya,
0217         Script_Tamil,
0218         Script_Telugu,
0219         Script_Kannada,
0220         Script_Malayalam,
0221         Script_Sinhala,
0222         Script_Thai,
0223         Script_Lao,
0224         Script_Tibetan,
0225         Script_Myanmar,
0226         Script_Georgian,
0227         Script_Hangul,
0228         Script_Ethiopic,
0229         Script_Cherokee,
0230         Script_CanadianAboriginal,
0231         Script_Ogham,
0232         Script_Runic,
0233         Script_Khmer,
0234         Script_Mongolian,
0235         Script_Hiragana,
0236         Script_Katakana,
0237         Script_Bopomofo,
0238         Script_Han,
0239         Script_Yi,
0240         Script_OldItalic,
0241         Script_Gothic,
0242         Script_Deseret,
0243         Script_Tagalog,
0244         Script_Hanunoo,
0245         Script_Buhid,
0246         Script_Tagbanwa,
0247         Script_Coptic,
0248 
0249         // Unicode 4.0 additions
0250         Script_Limbu,
0251         Script_TaiLe,
0252         Script_LinearB,
0253         Script_Ugaritic,
0254         Script_Shavian,
0255         Script_Osmanya,
0256         Script_Cypriot,
0257         Script_Braille,
0258 
0259         // Unicode 4.1 additions
0260         Script_Buginese,
0261         Script_NewTaiLue,
0262         Script_Glagolitic,
0263         Script_Tifinagh,
0264         Script_SylotiNagri,
0265         Script_OldPersian,
0266         Script_Kharoshthi,
0267 
0268         // Unicode 5.0 additions
0269         Script_Balinese,
0270         Script_Cuneiform,
0271         Script_Phoenician,
0272         Script_PhagsPa,
0273         Script_Nko,
0274 
0275         // Unicode 5.1 additions
0276         Script_Sundanese,
0277         Script_Lepcha,
0278         Script_OlChiki,
0279         Script_Vai,
0280         Script_Saurashtra,
0281         Script_KayahLi,
0282         Script_Rejang,
0283         Script_Lycian,
0284         Script_Carian,
0285         Script_Lydian,
0286         Script_Cham,
0287 
0288         // Unicode 5.2 additions
0289         Script_TaiTham,
0290         Script_TaiViet,
0291         Script_Avestan,
0292         Script_EgyptianHieroglyphs,
0293         Script_Samaritan,
0294         Script_Lisu,
0295         Script_Bamum,
0296         Script_Javanese,
0297         Script_MeeteiMayek,
0298         Script_ImperialAramaic,
0299         Script_OldSouthArabian,
0300         Script_InscriptionalParthian,
0301         Script_InscriptionalPahlavi,
0302         Script_OldTurkic,
0303         Script_Kaithi,
0304 
0305         // Unicode 6.0 additions
0306         Script_Batak,
0307         Script_Brahmi,
0308         Script_Mandaic,
0309 
0310         // Unicode 6.1 additions
0311         Script_Chakma,
0312         Script_MeroiticCursive,
0313         Script_MeroiticHieroglyphs,
0314         Script_Miao,
0315         Script_Sharada,
0316         Script_SoraSompeng,
0317         Script_Takri,
0318 
0319         // Unicode 7.0 additions
0320         Script_CaucasianAlbanian,
0321         Script_BassaVah,
0322         Script_Duployan,
0323         Script_Elbasan,
0324         Script_Grantha,
0325         Script_PahawhHmong,
0326         Script_Khojki,
0327         Script_LinearA,
0328         Script_Mahajani,
0329         Script_Manichaean,
0330         Script_MendeKikakui,
0331         Script_Modi,
0332         Script_Mro,
0333         Script_OldNorthArabian,
0334         Script_Nabataean,
0335         Script_Palmyrene,
0336         Script_PauCinHau,
0337         Script_OldPermic,
0338         Script_PsalterPahlavi,
0339         Script_Siddham,
0340         Script_Khudawadi,
0341         Script_Tirhuta,
0342         Script_WarangCiti,
0343 
0344         // Unicode 8.0 additions
0345         Script_Ahom,
0346         Script_AnatolianHieroglyphs,
0347         Script_Hatran,
0348         Script_Multani,
0349         Script_OldHungarian,
0350         Script_SignWriting,
0351 
0352         // Unicode 9.0 additions
0353         Script_Adlam,
0354         Script_Bhaiksuki,
0355         Script_Marchen,
0356         Script_Newa,
0357         Script_Osage,
0358         Script_Tangut,
0359 
0360         // Unicode 10.0 additions
0361         Script_MasaramGondi,
0362         Script_Nushu,
0363         Script_Soyombo,
0364         Script_ZanabazarSquare,
0365 
0366         // Unicode 12.1 additions
0367         Script_Dogra,
0368         Script_GunjalaGondi,
0369         Script_HanifiRohingya,
0370         Script_Makasar,
0371         Script_Medefaidrin,
0372         Script_OldSogdian,
0373         Script_Sogdian,
0374         Script_Elymaic,
0375         Script_Nandinagari,
0376         Script_NyiakengPuachueHmong,
0377         Script_Wancho,
0378 
0379         // Unicode 13.0 additions
0380         Script_Chorasmian,
0381         Script_DivesAkuru,
0382         Script_KhitanSmallScript,
0383         Script_Yezidi,
0384 
0385         // Unicode 14.0 additions
0386         Script_CyproMinoan,
0387         Script_OldUyghur,
0388         Script_Tangsa,
0389         Script_Toto,
0390         Script_Vithkuqi,
0391 
0392         // Unicode 15.0 additions
0393         Script_Kawi,
0394         Script_NagMundari,
0395 
0396         // Unicode 16.0 additions
0397         Script_Garay,
0398         Script_GurungKhema,
0399         Script_KiratRai,
0400         Script_OlOnal,
0401         Script_Sunuwar,
0402         Script_Todhri,
0403         Script_TuluTigalari,
0404 
0405         ScriptCount
0406     };
0407 
0408     enum Direction
0409     {
0410         DirL, DirR, DirEN, DirES, DirET, DirAN, DirCS, DirB, DirS, DirWS, DirON,
0411         DirLRE, DirLRO, DirAL, DirRLE, DirRLO, DirPDF, DirNSM, DirBN,
0412         DirLRI, DirRLI, DirFSI, DirPDI
0413     };
0414 
0415     enum Decomposition
0416     {
0417         NoDecomposition,
0418         Canonical,
0419         Font,
0420         NoBreak,
0421         Initial,
0422         Medial,
0423         Final,
0424         Isolated,
0425         Circle,
0426         Super,
0427         Sub,
0428         Vertical,
0429         Wide,
0430         Narrow,
0431         Small,
0432         Square,
0433         Compat,
0434         Fraction
0435     };
0436 
0437     enum JoiningType {
0438         Joining_None,
0439         Joining_Causing,
0440         Joining_Dual,
0441         Joining_Right,
0442         Joining_Left,
0443         Joining_Transparent
0444     };
0445 
0446     enum CombiningClass
0447     {
0448         Combining_BelowLeftAttached       = 200,
0449         Combining_BelowAttached           = 202,
0450         Combining_BelowRightAttached      = 204,
0451         Combining_LeftAttached            = 208,
0452         Combining_RightAttached           = 210,
0453         Combining_AboveLeftAttached       = 212,
0454         Combining_AboveAttached           = 214,
0455         Combining_AboveRightAttached      = 216,
0456 
0457         Combining_BelowLeft               = 218,
0458         Combining_Below                   = 220,
0459         Combining_BelowRight              = 222,
0460         Combining_Left                    = 224,
0461         Combining_Right                   = 226,
0462         Combining_AboveLeft               = 228,
0463         Combining_Above                   = 230,
0464         Combining_AboveRight              = 232,
0465 
0466         Combining_DoubleBelow             = 233,
0467         Combining_DoubleAbove             = 234,
0468         Combining_IotaSubscript           = 240
0469     };
0470 
0471     enum UnicodeVersion {
0472         Unicode_Unassigned,
0473         Unicode_1_1,
0474         Unicode_2_0,
0475         Unicode_2_1_2,
0476         Unicode_3_0,
0477         Unicode_3_1,
0478         Unicode_3_2,
0479         Unicode_4_0,
0480         Unicode_4_1,
0481         Unicode_5_0,
0482         Unicode_5_1,
0483         Unicode_5_2,
0484         Unicode_6_0,
0485         Unicode_6_1,
0486         Unicode_6_2,
0487         Unicode_6_3,
0488         Unicode_7_0,
0489         Unicode_8_0,
0490         Unicode_9_0,
0491         Unicode_10_0,
0492         Unicode_11_0,
0493         Unicode_12_0,
0494         Unicode_12_1,
0495         Unicode_13_0,
0496         Unicode_14_0,
0497         Unicode_15_0,
0498         Unicode_15_1,
0499         Unicode_16_0,
0500     };
0501 
0502     inline Category category() const noexcept { return QChar::category(ucs); }
0503     inline Direction direction() const noexcept { return QChar::direction(ucs); }
0504     inline JoiningType joiningType() const noexcept { return QChar::joiningType(ucs); }
0505     inline unsigned char combiningClass() const noexcept { return QChar::combiningClass(ucs); }
0506 
0507     inline QChar mirroredChar() const noexcept { return QChar(QChar::mirroredChar(ucs)); }
0508     inline bool hasMirrored() const noexcept { return QChar::hasMirrored(ucs); }
0509 
0510     QString decomposition() const;
0511     inline Decomposition decompositionTag() const noexcept { return QChar::decompositionTag(ucs); }
0512 
0513     inline int digitValue() const noexcept { return QChar::digitValue(ucs); }
0514     inline QChar toLower() const noexcept { return QChar(QChar::toLower(ucs)); }
0515     inline QChar toUpper() const noexcept { return QChar(QChar::toUpper(ucs)); }
0516     inline QChar toTitleCase() const noexcept { return QChar(QChar::toTitleCase(ucs)); }
0517     inline QChar toCaseFolded() const noexcept { return QChar(QChar::toCaseFolded(ucs)); }
0518 
0519     inline Script script() const noexcept { return QChar::script(ucs); }
0520 
0521     inline UnicodeVersion unicodeVersion() const noexcept { return QChar::unicodeVersion(ucs); }
0522 
0523     constexpr inline char toLatin1() const noexcept { return ucs > 0xff ? '\0' : char(ucs); }
0524     constexpr inline char16_t unicode() const noexcept { return ucs; }
0525     constexpr inline char16_t &unicode() noexcept { return ucs; }
0526 
0527     static constexpr QChar fromLatin1(char c) noexcept { return QLatin1Char(c); }
0528 
0529     constexpr inline bool isNull() const noexcept { return ucs == 0; }
0530 
0531     inline bool isPrint() const noexcept { return QChar::isPrint(ucs); }
0532     constexpr inline bool isSpace() const noexcept { return QChar::isSpace(ucs); }
0533     inline bool isMark() const noexcept { return QChar::isMark(ucs); }
0534     inline bool isPunct() const noexcept { return QChar::isPunct(ucs); }
0535     inline bool isSymbol() const noexcept { return QChar::isSymbol(ucs); }
0536     constexpr inline bool isLetter() const noexcept { return QChar::isLetter(ucs); }
0537     constexpr inline bool isNumber() const noexcept { return QChar::isNumber(ucs); }
0538     constexpr inline bool isLetterOrNumber() const noexcept { return QChar::isLetterOrNumber(ucs); }
0539     constexpr inline bool isDigit() const noexcept { return QChar::isDigit(ucs); }
0540     constexpr inline bool isLower() const noexcept { return QChar::isLower(ucs); }
0541     constexpr inline bool isUpper() const noexcept { return QChar::isUpper(ucs); }
0542     constexpr inline bool isTitleCase() const noexcept { return QChar::isTitleCase(ucs); }
0543 
0544     constexpr inline bool isNonCharacter() const noexcept { return QChar::isNonCharacter(ucs); }
0545     constexpr inline bool isHighSurrogate() const noexcept { return QChar::isHighSurrogate(ucs); }
0546     constexpr inline bool isLowSurrogate() const noexcept { return QChar::isLowSurrogate(ucs); }
0547     constexpr inline bool isSurrogate() const noexcept { return QChar::isSurrogate(ucs); }
0548 
0549     constexpr inline uchar cell() const noexcept { return uchar(ucs & 0xff); }
0550     constexpr inline uchar row() const noexcept { return uchar((ucs>>8)&0xff); }
0551     constexpr inline void setCell(uchar acell) noexcept { ucs = char16_t((ucs & 0xff00) + acell); }
0552     constexpr inline void setRow(uchar arow) noexcept { ucs = char16_t((char16_t(arow)<<8) + (ucs&0xff)); }
0553 
0554     static constexpr inline bool isNonCharacter(char32_t ucs4) noexcept
0555     {
0556         return ucs4 >= 0xfdd0 && (ucs4 <= 0xfdef || (ucs4 & 0xfffe) == 0xfffe);
0557     }
0558     static constexpr inline bool isHighSurrogate(char32_t ucs4) noexcept
0559     {
0560         return (ucs4 & 0xfffffc00) == 0xd800; // 0xd800 + up to 1023 (0x3ff)
0561     }
0562     static constexpr inline bool isLowSurrogate(char32_t ucs4) noexcept
0563     {
0564         return (ucs4 & 0xfffffc00) == 0xdc00; // 0xdc00 + up to 1023 (0x3ff)
0565     }
0566     static constexpr inline bool isSurrogate(char32_t ucs4) noexcept
0567     {
0568         return (ucs4 - 0xd800u < 2048u);
0569     }
0570     static constexpr inline bool requiresSurrogates(char32_t ucs4) noexcept
0571     {
0572         return (ucs4 >= 0x10000);
0573     }
0574     static constexpr inline char32_t surrogateToUcs4(char16_t high, char16_t low) noexcept
0575     {
0576         // 0x010000 through 0x10ffff, provided params are actual high, low surrogates.
0577         // 0x010000 + ((high - 0xd800) << 10) + (low - 0xdc00), optimized:
0578         return (char32_t(high)<<10) + low - 0x35fdc00;
0579     }
0580     static constexpr inline char32_t surrogateToUcs4(QChar high, QChar low) noexcept
0581     {
0582         return surrogateToUcs4(high.ucs, low.ucs);
0583     }
0584     static constexpr inline char16_t highSurrogate(char32_t ucs4) noexcept
0585     {
0586         return char16_t((ucs4>>10) + 0xd7c0);
0587     }
0588     static constexpr inline char16_t lowSurrogate(char32_t ucs4) noexcept
0589     {
0590         return char16_t(ucs4%0x400 + 0xdc00);
0591     }
0592 
0593     static Category QT_CHAR_FASTCALL category(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION;
0594     static Direction QT_CHAR_FASTCALL direction(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION;
0595     static JoiningType QT_CHAR_FASTCALL joiningType(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION;
0596     static unsigned char QT_CHAR_FASTCALL combiningClass(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION;
0597 
0598     static char32_t QT_CHAR_FASTCALL mirroredChar(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION;
0599     static bool QT_CHAR_FASTCALL hasMirrored(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION;
0600 
0601     static QString QT_CHAR_FASTCALL decomposition(char32_t ucs4);
0602     static Decomposition QT_CHAR_FASTCALL decompositionTag(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION;
0603 
0604     static int QT_CHAR_FASTCALL digitValue(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION;
0605     static char32_t QT_CHAR_FASTCALL toLower(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION;
0606     static char32_t QT_CHAR_FASTCALL toUpper(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION;
0607     static char32_t QT_CHAR_FASTCALL toTitleCase(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION;
0608     static char32_t QT_CHAR_FASTCALL toCaseFolded(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION;
0609 
0610     static Script QT_CHAR_FASTCALL script(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION;
0611 
0612     static UnicodeVersion QT_CHAR_FASTCALL unicodeVersion(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION;
0613 
0614     static UnicodeVersion QT_CHAR_FASTCALL currentUnicodeVersion() noexcept Q_DECL_CONST_FUNCTION;
0615 
0616     static bool QT_CHAR_FASTCALL isPrint(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION;
0617     static constexpr inline bool isSpace(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION
0618     {
0619         // note that [0x09..0x0d] + 0x85 are exceptional Cc-s and must be handled explicitly
0620         return ucs4 == 0x20 || (ucs4 <= 0x0d && ucs4 >= 0x09)
0621                 || (ucs4 > 127 && (ucs4 == 0x85 || ucs4 == 0xa0 || QChar::isSpace_helper(ucs4)));
0622     }
0623     static bool QT_CHAR_FASTCALL isMark(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION;
0624     static bool QT_CHAR_FASTCALL isPunct(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION;
0625     static bool QT_CHAR_FASTCALL isSymbol(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION;
0626     static constexpr inline bool isLetter(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION
0627     {
0628         return (ucs4 >= 'A' && ucs4 <= 'z' && (ucs4 >= 'a' || ucs4 <= 'Z'))
0629                 || (ucs4 > 127 && QChar::isLetter_helper(ucs4));
0630     }
0631     static constexpr inline bool isNumber(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION
0632     { return (ucs4 <= '9' && ucs4 >= '0') || (ucs4 > 127 && QChar::isNumber_helper(ucs4)); }
0633     static constexpr inline bool isLetterOrNumber(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION
0634     {
0635         return (ucs4 >= 'A' && ucs4 <= 'z' && (ucs4 >= 'a' || ucs4 <= 'Z'))
0636                 || (ucs4 >= '0' && ucs4 <= '9')
0637                 || (ucs4 > 127 && QChar::isLetterOrNumber_helper(ucs4));
0638     }
0639     static constexpr inline bool isDigit(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION
0640     { return (ucs4 <= '9' && ucs4 >= '0') || (ucs4 > 127 && QChar::category(ucs4) == Number_DecimalDigit); }
0641     static constexpr inline bool isLower(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION
0642     { return (ucs4 <= 'z' && ucs4 >= 'a') || (ucs4 > 127 && QChar::category(ucs4) == Letter_Lowercase); }
0643     static constexpr inline bool isUpper(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION
0644     { return (ucs4 <= 'Z' && ucs4 >= 'A') || (ucs4 > 127 && QChar::category(ucs4) == Letter_Uppercase); }
0645     static constexpr inline bool isTitleCase(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION
0646     { return ucs4 > 127 && QChar::category(ucs4) == Letter_Titlecase; }
0647 
0648     friend constexpr bool comparesEqual(const QChar &lhs, const QChar &rhs) noexcept
0649     { return lhs.ucs == rhs.ucs; }
0650     friend constexpr Qt::strong_ordering
0651     compareThreeWay(const QChar &lhs, const QChar &rhs) noexcept
0652     { return Qt::compareThreeWay(lhs.ucs, rhs.ucs); }
0653     Q_DECLARE_STRONGLY_ORDERED_LITERAL_TYPE(QChar)
0654 
0655     friend constexpr bool comparesEqual(const QChar &lhs, std::nullptr_t) noexcept
0656     { return lhs.isNull(); }
0657     friend constexpr Qt::strong_ordering
0658     compareThreeWay(const QChar &lhs, std::nullptr_t) noexcept
0659     { return lhs.isNull() ? Qt::strong_ordering::equivalent : Qt::strong_ordering::greater; }
0660     Q_DECLARE_STRONGLY_ORDERED_LITERAL_TYPE(QChar, std::nullptr_t)
0661 
0662 private:
0663     static bool QT_CHAR_FASTCALL isSpace_helper(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION;
0664     static bool QT_CHAR_FASTCALL isLetter_helper(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION;
0665     static bool QT_CHAR_FASTCALL isNumber_helper(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION;
0666     static bool QT_CHAR_FASTCALL isLetterOrNumber_helper(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION;
0667 
0668     // defined in qstring.cpp, because we need to go via QUtf8StringView
0669     static bool QT_CHAR_FASTCALL
0670     equal_helper(QChar lhs, const char *rhs) noexcept Q_DECL_CONST_FUNCTION;
0671     static int QT_CHAR_FASTCALL
0672     compare_helper(QChar lhs, const char *rhs) noexcept Q_DECL_CONST_FUNCTION;
0673 
0674 #if !defined(QT_NO_CAST_FROM_ASCII) && !defined(QT_RESTRICTED_CAST_FROM_ASCII)
0675     Q_WEAK_OVERLOAD
0676     friend bool comparesEqual(const QChar &lhs, const char *rhs) noexcept
0677     { return equal_helper(lhs, rhs); }
0678     Q_WEAK_OVERLOAD
0679     friend Qt::strong_ordering compareThreeWay(const QChar &lhs, const char *rhs) noexcept
0680     {
0681         const int res = compare_helper(lhs, rhs);
0682         return Qt::compareThreeWay(res, 0);
0683     }
0684     Q_DECLARE_STRONGLY_ORDERED(QChar, const char *, Q_WEAK_OVERLOAD QT_ASCII_CAST_WARN)
0685 #endif // !defined(QT_NO_CAST_FROM_ASCII) && !defined(QT_RESTRICTED_CAST_FROM_ASCII)
0686 
0687     char16_t ucs;
0688 };
0689 #undef QT_CHAR_FASTCALL
0690 
0691 Q_DECLARE_TYPEINFO(QChar, Q_PRIMITIVE_TYPE);
0692 
0693 #ifndef QT_NO_DATASTREAM
0694 Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, QChar);
0695 Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QChar &);
0696 #endif
0697 
0698 namespace Qt {
0699 inline namespace Literals {
0700 inline namespace StringLiterals {
0701 
0702 constexpr inline QLatin1Char operator""_L1(char ch) noexcept
0703 {
0704     return QLatin1Char(ch);
0705 }
0706 
0707 } // StringLiterals
0708 } // Literals
0709 } // Qt
0710 
0711 QT_END_NAMESPACE
0712 
0713 namespace std {
0714 template <>
0715 struct hash<QT_PREPEND_NAMESPACE(QChar)>
0716 {
0717     template <typename = void> // for transparent constexpr tracking
0718     constexpr size_t operator()(QT_PREPEND_NAMESPACE(QChar) c) const
0719         noexcept(noexcept(std::hash<char16_t>{}(u' ')))
0720     {
0721         return std::hash<char16_t>{}(c.unicode());
0722     }
0723 };
0724 } // namespace std
0725 
0726 #endif // QCHAR_H
0727 
0728 #include <QtCore/qstringview.h> // for QChar::fromUcs4() definition