Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qchar.h
Go to the documentation of this file.
1// Copyright (C) 2020 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QCHAR_H
5#define QCHAR_H
6
7#include <QtCore/qglobal.h>
8#include <QtCore/qcompare.h>
9
10#include <functional> // for std::hash
11
12QT_BEGIN_NAMESPACE
13
14class QString;
15
17{
18public:
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)); }
22
23 friend constexpr bool
24 comparesEqual(const QLatin1Char &lhs, const QLatin1Char &rhs) noexcept
25 { return lhs.ch == rhs.ch; }
26 friend constexpr Qt::strong_ordering
27 compareThreeWay(const QLatin1Char &lhs, const QLatin1Char &rhs) noexcept
28 { return Qt::compareThreeWay(uchar(lhs.ch), uchar(rhs.ch)); }
30
31 friend constexpr bool comparesEqual(const QLatin1Char &lhs, char rhs) noexcept
32 { return lhs.toLatin1() == rhs; }
33 friend constexpr Qt::strong_ordering
34 compareThreeWay(const QLatin1Char &lhs, char rhs) noexcept
35 { return Qt::compareThreeWay(uchar(lhs.toLatin1()), uchar(rhs)); }
37
38private:
39 friend class QChar;
40 // this is for QChar's ctor only:
41 explicit constexpr operator char16_t() const noexcept { return unicode(); }
42
43 char ch;
44};
45
46#define QT_CHAR_FASTCALL QT7_ONLY(Q_CORE_EXPORT) QT_FASTCALL
47class QT6_ONLY(Q_CORE_EXPORT) QChar {
48public:
49 enum SpecialCharacter {
50 Null = 0x0000,
51 Tabulation = 0x0009,
52 LineFeed = 0x000a,
53 FormFeed = 0x000c,
54 CarriageReturn = 0x000d,
55 Space = 0x0020,
56 Nbsp = 0x00a0,
57 SoftHyphen = 0x00ad,
58 ReplacementCharacter = 0xfffd,
59 ObjectReplacementCharacter = 0xfffc,
60 ByteOrderMark = 0xfeff,
61 ByteOrderSwapped = 0xfffe,
62 ParagraphSeparator = 0x2029,
63 LineSeparator = 0x2028,
64 VisualTabCharacter = 0x2192,
65 LastValidCodePoint = 0x10ffff
66 };
67
68#ifdef QT_IMPLICIT_QCHAR_CONSTRUCTION
69#error This macro has been removed in Qt 6.8.
70#endif
71private:
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>
81 >;
82 template <typename Char>
83 using is_explicit_conversion_char = std::disjunction<
84 std::is_same<Char, char32_t>, // implicit conversion to uint(?) before 6.8
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>
88 >;
89 template <typename Char>
90 using is_conversion_char = std::disjunction<
91 is_implicit_conversion_char<Char>,
92 is_explicit_conversion_char<Char>
93 >;
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>
112 >;
113public:
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) {}
117#endif
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)) {}
128#endif
129#endif // QT_CORE_REMOVED_SINCE(6, 9)
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))) {}
135
136#ifndef QT_NO_CAST_FROM_ASCII
137 // Always implicit -- allow for 'x' => QChar conversions
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)) { }
140#endif
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) { }
146#endif
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) { }
149#endif
150#endif
151
152 static constexpr QChar fromUcs2(char16_t c) noexcept { return QChar{c}; }
153 static constexpr inline auto fromUcs4(char32_t c) noexcept;
154
155 // Unicode information
156
157 enum Category
158 {
159 Mark_NonSpacing, // Mn
160 Mark_SpacingCombining, // Mc
161 Mark_Enclosing, // Me
162
163 Number_DecimalDigit, // Nd
164 Number_Letter, // Nl
165 Number_Other, // No
166
167 Separator_Space, // Zs
168 Separator_Line, // Zl
169 Separator_Paragraph, // Zp
170
171 Other_Control, // Cc
172 Other_Format, // Cf
173 Other_Surrogate, // Cs
174 Other_PrivateUse, // Co
175 Other_NotAssigned, // Cn
176
177 Letter_Uppercase, // Lu
178 Letter_Lowercase, // Ll
179 Letter_Titlecase, // Lt
180 Letter_Modifier, // Lm
181 Letter_Other, // Lo
182
183 Punctuation_Connector, // Pc
184 Punctuation_Dash, // Pd
185 Punctuation_Open, // Ps
186 Punctuation_Close, // Pe
187 Punctuation_InitialQuote, // Pi
188 Punctuation_FinalQuote, // Pf
189 Punctuation_Other, // Po
190
191 Symbol_Math, // Sm
192 Symbol_Currency, // Sc
193 Symbol_Modifier, // Sk
194 Symbol_Other // So
195 };
196
197 enum Script
198 {
199 Script_Unknown,
200 Script_Inherited,
201 Script_Common,
202
203 Script_Latin,
204 Script_Greek,
205 Script_Cyrillic,
206 Script_Armenian,
207 Script_Hebrew,
208 Script_Arabic,
209 Script_Syriac,
210 Script_Thaana,
211 Script_Devanagari,
212 Script_Bengali,
213 Script_Gurmukhi,
214 Script_Gujarati,
215 Script_Oriya,
216 Script_Tamil,
217 Script_Telugu,
218 Script_Kannada,
219 Script_Malayalam,
220 Script_Sinhala,
221 Script_Thai,
222 Script_Lao,
223 Script_Tibetan,
224 Script_Myanmar,
225 Script_Georgian,
226 Script_Hangul,
227 Script_Ethiopic,
228 Script_Cherokee,
229 Script_CanadianAboriginal,
230 Script_Ogham,
231 Script_Runic,
232 Script_Khmer,
233 Script_Mongolian,
234 Script_Hiragana,
235 Script_Katakana,
236 Script_Bopomofo,
237 Script_Han,
238 Script_Yi,
239 Script_OldItalic,
240 Script_Gothic,
241 Script_Deseret,
242 Script_Tagalog,
243 Script_Hanunoo,
244 Script_Buhid,
245 Script_Tagbanwa,
246 Script_Coptic,
247
248 // Unicode 4.0 additions
249 Script_Limbu,
250 Script_TaiLe,
251 Script_LinearB,
252 Script_Ugaritic,
253 Script_Shavian,
254 Script_Osmanya,
255 Script_Cypriot,
256 Script_Braille,
257
258 // Unicode 4.1 additions
259 Script_Buginese,
260 Script_NewTaiLue,
261 Script_Glagolitic,
262 Script_Tifinagh,
263 Script_SylotiNagri,
264 Script_OldPersian,
265 Script_Kharoshthi,
266
267 // Unicode 5.0 additions
268 Script_Balinese,
269 Script_Cuneiform,
270 Script_Phoenician,
271 Script_PhagsPa,
272 Script_Nko,
273
274 // Unicode 5.1 additions
275 Script_Sundanese,
276 Script_Lepcha,
277 Script_OlChiki,
278 Script_Vai,
279 Script_Saurashtra,
280 Script_KayahLi,
281 Script_Rejang,
282 Script_Lycian,
283 Script_Carian,
284 Script_Lydian,
285 Script_Cham,
286
287 // Unicode 5.2 additions
288 Script_TaiTham,
289 Script_TaiViet,
290 Script_Avestan,
291 Script_EgyptianHieroglyphs,
292 Script_Samaritan,
293 Script_Lisu,
294 Script_Bamum,
295 Script_Javanese,
296 Script_MeeteiMayek,
297 Script_ImperialAramaic,
298 Script_OldSouthArabian,
299 Script_InscriptionalParthian,
300 Script_InscriptionalPahlavi,
301 Script_OldTurkic,
302 Script_Kaithi,
303
304 // Unicode 6.0 additions
305 Script_Batak,
306 Script_Brahmi,
307 Script_Mandaic,
308
309 // Unicode 6.1 additions
310 Script_Chakma,
311 Script_MeroiticCursive,
312 Script_MeroiticHieroglyphs,
313 Script_Miao,
314 Script_Sharada,
315 Script_SoraSompeng,
316 Script_Takri,
317
318 // Unicode 7.0 additions
319 Script_CaucasianAlbanian,
320 Script_BassaVah,
321 Script_Duployan,
322 Script_Elbasan,
323 Script_Grantha,
324 Script_PahawhHmong,
325 Script_Khojki,
326 Script_LinearA,
327 Script_Mahajani,
328 Script_Manichaean,
329 Script_MendeKikakui,
330 Script_Modi,
331 Script_Mro,
332 Script_OldNorthArabian,
333 Script_Nabataean,
334 Script_Palmyrene,
335 Script_PauCinHau,
336 Script_OldPermic,
337 Script_PsalterPahlavi,
338 Script_Siddham,
339 Script_Khudawadi,
340 Script_Tirhuta,
341 Script_WarangCiti,
342
343 // Unicode 8.0 additions
344 Script_Ahom,
345 Script_AnatolianHieroglyphs,
346 Script_Hatran,
347 Script_Multani,
348 Script_OldHungarian,
349 Script_SignWriting,
350
351 // Unicode 9.0 additions
352 Script_Adlam,
353 Script_Bhaiksuki,
354 Script_Marchen,
355 Script_Newa,
356 Script_Osage,
357 Script_Tangut,
358
359 // Unicode 10.0 additions
360 Script_MasaramGondi,
361 Script_Nushu,
362 Script_Soyombo,
363 Script_ZanabazarSquare,
364
365 // Unicode 12.1 additions
366 Script_Dogra,
367 Script_GunjalaGondi,
368 Script_HanifiRohingya,
369 Script_Makasar,
370 Script_Medefaidrin,
371 Script_OldSogdian,
372 Script_Sogdian,
373 Script_Elymaic,
374 Script_Nandinagari,
375 Script_NyiakengPuachueHmong,
376 Script_Wancho,
377
378 // Unicode 13.0 additions
379 Script_Chorasmian,
380 Script_DivesAkuru,
381 Script_KhitanSmallScript,
382 Script_Yezidi,
383
384 // Unicode 14.0 additions
385 Script_CyproMinoan,
386 Script_OldUyghur,
387 Script_Tangsa,
388 Script_Toto,
389 Script_Vithkuqi,
390
391 // Unicode 15.0 additions
392 Script_Kawi,
393 Script_NagMundari,
394
395 // Unicode 16.0 additions
396 Script_Garay,
397 Script_GurungKhema,
398 Script_KiratRai,
399 Script_OlOnal,
400 Script_Sunuwar,
401 Script_Todhri,
402 Script_TuluTigalari,
403
404 ScriptCount
405 };
406
407 enum Direction
408 {
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
412 };
413
414 enum Decomposition
415 {
416 NoDecomposition,
417 Canonical,
418 Font,
419 NoBreak,
420 Initial,
421 Medial,
422 Final,
423 Isolated,
424 Circle,
425 Super,
426 Sub,
427 Vertical,
428 Wide,
429 Narrow,
430 Small,
431 Square,
432 Compat,
433 Fraction
434 };
435
436 enum JoiningType {
437 Joining_None,
438 Joining_Causing,
439 Joining_Dual,
440 Joining_Right,
441 Joining_Left,
442 Joining_Transparent
443 };
444
445 enum CombiningClass
446 {
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,
455
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,
464
465 Combining_DoubleBelow = 233,
466 Combining_DoubleAbove = 234,
467 Combining_IotaSubscript = 240
468 };
469
470 enum UnicodeVersion {
471 Unicode_Unassigned,
472 Unicode_1_1,
473 Unicode_2_0,
474 Unicode_2_1_2,
475 Unicode_3_0,
476 Unicode_3_1,
477 Unicode_3_2,
478 Unicode_4_0,
479 Unicode_4_1,
480 Unicode_5_0,
481 Unicode_5_1,
482 Unicode_5_2,
483 Unicode_6_0,
484 Unicode_6_1,
485 Unicode_6_2,
486 Unicode_6_3,
487 Unicode_7_0,
488 Unicode_8_0,
489 Unicode_9_0,
490 Unicode_10_0,
491 Unicode_11_0,
492 Unicode_12_0,
493 Unicode_12_1,
494 Unicode_13_0,
495 Unicode_14_0,
496 Unicode_15_0,
497 Unicode_15_1,
498 Unicode_16_0,
499 };
500
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); }
505
506 inline QChar mirroredChar() const noexcept { return QChar(QChar::mirroredChar(ucs)); }
507 inline bool hasMirrored() const noexcept { return QChar::hasMirrored(ucs); }
508
509 QString decomposition() const;
510 inline Decomposition decompositionTag() const noexcept { return QChar::decompositionTag(ucs); }
511
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)); }
517
518 inline Script script() const noexcept { return QChar::script(ucs); }
519
520 inline UnicodeVersion unicodeVersion() const noexcept { return QChar::unicodeVersion(ucs); }
521
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; }
525
526 static constexpr QChar fromLatin1(char c) noexcept { return QLatin1Char(c); }
527
528 constexpr inline bool isNull() const noexcept { return ucs == 0; }
529
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); }
542
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); }
547
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)); }
552
553 static constexpr inline bool isNonCharacter(char32_t ucs4) noexcept
554 {
555 return ucs4 >= 0xfdd0 && (ucs4 <= 0xfdef || (ucs4 & 0xfffe) == 0xfffe);
556 }
557 static constexpr inline bool isHighSurrogate(char32_t ucs4) noexcept
558 {
559 return (ucs4 & 0xfffffc00) == 0xd800; // 0xd800 + up to 1023 (0x3ff)
560 }
561 static constexpr inline bool isLowSurrogate(char32_t ucs4) noexcept
562 {
563 return (ucs4 & 0xfffffc00) == 0xdc00; // 0xdc00 + up to 1023 (0x3ff)
564 }
565 static constexpr inline bool isSurrogate(char32_t ucs4) noexcept
566 {
567 return (ucs4 - 0xd800u < 2048u);
568 }
569 static constexpr inline bool requiresSurrogates(char32_t ucs4) noexcept
570 {
571 return (ucs4 >= 0x10000);
572 }
573 static constexpr inline char32_t surrogateToUcs4(char16_t high, char16_t low) noexcept
574 {
575 // 0x010000 through 0x10ffff, provided params are actual high, low surrogates.
576 // 0x010000 + ((high - 0xd800) << 10) + (low - 0xdc00), optimized:
577 return (char32_t(high)<<10) + low - 0x35fdc00;
578 }
579 static constexpr inline char32_t surrogateToUcs4(QChar high, QChar low) noexcept
580 {
581 return surrogateToUcs4(high.ucs, low.ucs);
582 }
583 static constexpr inline char16_t highSurrogate(char32_t ucs4) noexcept
584 {
585 return char16_t((ucs4>>10) + 0xd7c0);
586 }
587 static constexpr inline char16_t lowSurrogate(char32_t ucs4) noexcept
588 {
589 return char16_t(ucs4%0x400 + 0xdc00);
590 }
591
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;
596
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;
599
600 static QString QT_CHAR_FASTCALL decomposition(char32_t ucs4);
601 static Decomposition QT_CHAR_FASTCALL decompositionTag(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION;
602
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;
608
609 static Script QT_CHAR_FASTCALL script(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION;
610
611 static UnicodeVersion QT_CHAR_FASTCALL unicodeVersion(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION;
612
613 static UnicodeVersion QT_CHAR_FASTCALL currentUnicodeVersion() noexcept Q_DECL_CONST_FUNCTION;
614
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
617 {
618 // note that [0x09..0x0d] + 0x85 are exceptional Cc-s and must be handled explicitly
619 return ucs4 == 0x20 || (ucs4 <= 0x0d && ucs4 >= 0x09)
620 || (ucs4 > 127 && (ucs4 == 0x85 || ucs4 == 0xa0 || QChar::isSpace_helper(ucs4)));
621 }
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
626 {
627 return (ucs4 >= 'A' && ucs4 <= 'z' && (ucs4 >= 'a' || ucs4 <= 'Z'))
628 || (ucs4 > 127 && QChar::isLetter_helper(ucs4));
629 }
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
633 {
634 return (ucs4 >= 'A' && ucs4 <= 'z' && (ucs4 >= 'a' || ucs4 <= 'Z'))
635 || (ucs4 >= '0' && ucs4 <= '9')
636 || (ucs4 > 127 && QChar::isLetterOrNumber_helper(ucs4));
637 }
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; }
646
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)
653
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)
660
661private:
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;
666
667 // defined in qstring.cpp, because we need to go via QUtf8StringView
668 static bool QT_CHAR_FASTCALL
669 equal_helper(QChar lhs, const char *rhs) noexcept Q_DECL_CONST_FUNCTION;
670 static int QT_CHAR_FASTCALL
671 compare_helper(QChar lhs, const char *rhs) noexcept Q_DECL_CONST_FUNCTION;
672
673#if !defined(QT_NO_CAST_FROM_ASCII) && !defined(QT_RESTRICTED_CAST_FROM_ASCII)
674 Q_WEAK_OVERLOAD
675 friend bool comparesEqual(const QChar &lhs, const char *rhs) noexcept
676 { return equal_helper(lhs, rhs); }
677 Q_WEAK_OVERLOAD
678 friend Qt::strong_ordering compareThreeWay(const QChar &lhs, const char *rhs) noexcept
679 {
680 const int res = compare_helper(lhs, rhs);
681 return Qt::compareThreeWay(res, 0);
682 }
683 Q_DECLARE_STRONGLY_ORDERED(QChar, const char *, Q_WEAK_OVERLOAD QT_ASCII_CAST_WARN)
684#endif // !defined(QT_NO_CAST_FROM_ASCII) && !defined(QT_RESTRICTED_CAST_FROM_ASCII)
685
686 char16_t ucs;
687};
688#undef QT_CHAR_FASTCALL
689
691
692namespace Qt {
693inline namespace Literals {
694inline namespace StringLiterals {
695
696constexpr inline QLatin1Char operator""_L1(char ch) noexcept
697{
698 return QLatin1Char(ch);
699}
700
701} // StringLiterals
702} // Literals
703} // Qt
704
705QT_END_NAMESPACE
706
707namespace std {
708template <>
710{
711 template <typename = void> // for transparent constexpr tracking
713 noexcept(noexcept(std::hash<char16_t>{}(u' ')))
714 {
715 return std::hash<char16_t>{}(c.unicode());
716 }
717};
718} // namespace std
719
720#endif // QCHAR_H
721
722#include <QtCore/qstringview.h> // for QChar::fromUcs4() definition
static constexpr unsigned short specialCaseMap[]
constexpr unsigned int MaxSpecialCaseLength
static constexpr unsigned short uc_ligature_map[]
constexpr QLatin1Char operator""_L1(char ch) noexcept
Definition qchar.h:696
Definition qcompare.h:76
bool operator<(const UCS2SurrogatePair &ligature, char32_t u1)
Definition qchar.cpp:1886
static constexpr quint32 Hangul_VCount
Definition qchar.cpp:1397
static constexpr char32_t Hangul_SBase
Definition qchar.cpp:1392
static constexpr char32_t Hangul_VBase
Definition qchar.cpp:1394
bool operator<(ushort u1, const UCS2Pair &ligature)
Definition qchar.cpp:1872
#define FLAG(x)
Definition qchar.cpp:13
static constexpr quint32 Hangul_LCount
Definition qchar.cpp:1396
static char32_t ligatureHelper(char32_t u1, char32_t u2)
Definition qchar.cpp:1889
bool operator<(const UCS2Pair &ligature, ushort u1)
Definition qchar.cpp:1874
static void canonicalOrderHelper(QString *str, QChar::UnicodeVersion version, qsizetype from)
Definition qchar.cpp:1989
static constexpr char32_t Hangul_LBase
Definition qchar.cpp:1393
static constexpr char32_t Hangul_TBase
Definition qchar.cpp:1395
bool operator<(char32_t u1, const UCS2SurrogatePair &ligature)
Definition qchar.cpp:1884
static char32_t foldCase(char32_t ch, char32_t &last) noexcept
Definition qchar.cpp:1687
bool operator<(const UCS2SurrogatePair &ligature1, const UCS2SurrogatePair &ligature2)
Definition qchar.cpp:1882
bool operator<(const UCS2Pair &ligature1, const UCS2Pair &ligature2)
Definition qchar.cpp:1870
static auto fullConvertCase(char32_t uc, QUnicodeTables::Case which) noexcept
Definition qchar.cpp:1555
static constexpr quint32 Hangul_NCount
Definition qchar.cpp:1399
static void decomposeHelper(QString *str, bool canonical, QChar::UnicodeVersion version, qsizetype from)
Definition qchar.cpp:1829
static void composeHelper(QString *str, QChar::UnicodeVersion version, qsizetype from)
Definition qchar.cpp:1929
static constexpr quint32 Hangul_SCount
Definition qchar.cpp:1400
static bool normalizationQuickCheckHelper(QString *str, QString::NormalizationForm mode, qsizetype from, qsizetype *lastStable)
Definition qchar.cpp:2071
static QChar foldCase(QChar ch) noexcept
Definition qchar.cpp:1701
static constexpr quint32 Hangul_TCount
Definition qchar.cpp:1398
static char16_t foldCase(char16_t ch) noexcept
Definition qchar.cpp:1696
static char32_t foldCase(const char16_t *ch, const char16_t *start)
Definition qchar.cpp:1679
#define QT_CHAR_FASTCALL
Definition qchar.h:46
uint QT_FASTCALL fetch1Pixel< QPixelLayout::BPP1LSB >(const uchar *src, int index)
Q_DECLARE_TYPEINFO(QObjectPrivate::ConnectionList, Q_RELOCATABLE_TYPE)
#define GET_LIGATURE_INDEX(ucs4)
#define GET_DECOMPOSITION_INDEX(ucs4)
#define UNICODE_DATA_VERSION
\inmodule QtCore \reentrant
Definition qchar.h:17
friend constexpr Qt::strong_ordering compareThreeWay(const QLatin1Char &lhs, const QLatin1Char &rhs) noexcept
Definition qchar.h:27
constexpr char16_t unicode() const noexcept
Converts a Latin-1 character to an 16-bit-encoded Unicode representation of the character.
Definition qchar.h:21
friend constexpr bool comparesEqual(const QLatin1Char &lhs, const QLatin1Char &rhs) noexcept
Definition qchar.h:24
constexpr char toLatin1() const noexcept
Converts a Latin-1 character to an 8-bit ASCII representation of the character.
Definition qchar.h:20
constexpr QLatin1Char(char c) noexcept
Constructs a Latin-1 character for c.
Definition qchar.h:19
ushort u1
Definition qchar.cpp:1866
ushort u2
Definition qchar.cpp:1867