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// Qt-Security score:critical reason:data-parser
4
5#ifndef QCHAR_H
6#define QCHAR_H
7
8#include <QtCore/qglobal.h>
9#include <QtCore/qcompare.h>
10
11#include <functional> // for std::hash
12
13QT_BEGIN_NAMESPACE
14
15class QString;
16
18{
19public:
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)); }
23
24 friend constexpr bool
25 comparesEqual(const QLatin1Char &lhs, const QLatin1Char &rhs) noexcept
26 { return lhs.ch == rhs.ch; }
27 friend constexpr Qt::strong_ordering
28 compareThreeWay(const QLatin1Char &lhs, const QLatin1Char &rhs) noexcept
29 { return Qt::compareThreeWay(uchar(lhs.ch), uchar(rhs.ch)); }
31
32 friend constexpr bool comparesEqual(const QLatin1Char &lhs, char rhs) noexcept
33 { return lhs.toLatin1() == rhs; }
34 friend constexpr Qt::strong_ordering
35 compareThreeWay(const QLatin1Char &lhs, char rhs) noexcept
36 { return Qt::compareThreeWay(uchar(lhs.toLatin1()), uchar(rhs)); }
37 Q_DECLARE_STRONGLY_ORDERED_LITERAL_TYPE(QLatin1Char, char)
38
39private:
40 friend class QChar;
41 // this is for QChar's ctor only:
42 explicit constexpr operator char16_t() const noexcept { return unicode(); }
43
44 char ch;
45};
46
47#define QT_CHAR_FASTCALL QT7_ONLY(Q_CORE_EXPORT) QT_FASTCALL
48class QT6_ONLY(Q_CORE_EXPORT) QChar {
49public:
50 enum SpecialCharacter {
51 Null = 0x0000,
52 Tabulation = 0x0009,
53 LineFeed = 0x000a,
54 FormFeed = 0x000c,
55 CarriageReturn = 0x000d,
56 Space = 0x0020,
57 Nbsp = 0x00a0,
58 SoftHyphen = 0x00ad,
59 ReplacementCharacter = 0xfffd,
60 ObjectReplacementCharacter = 0xfffc,
61 ByteOrderMark = 0xfeff,
62 ByteOrderSwapped = 0xfffe,
63 ParagraphSeparator = 0x2029,
64 LineSeparator = 0x2028,
65 VisualTabCharacter = 0x2192,
66 LastValidCodePoint = 0x10ffff
67 };
68
69#ifdef QT_IMPLICIT_QCHAR_CONSTRUCTION
70#error This macro has been removed in Qt 6.8.
71#endif
72private:
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>
82 >;
83 template <typename Char>
84 using is_explicit_conversion_char = std::disjunction<
85 std::is_same<Char, char32_t>, // implicit conversion to uint(?) before 6.8
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>
89 >;
90 template <typename Char>
91 using is_conversion_char = std::disjunction<
92 is_implicit_conversion_char<Char>,
93 is_explicit_conversion_char<Char>
94 >;
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>
113 >;
114public:
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) {}
118#endif
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)) {}
129#endif
130#endif // QT_CORE_REMOVED_SINCE(6, 9)
131#ifdef Q_QDOC
132 constexpr explicit QChar(char32_t ch) noexcept;
133#endif
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))) {}
139
140#ifndef QT_NO_CAST_FROM_ASCII
141 // Always implicit -- allow for 'x' => QChar conversions
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)) { }
144#endif
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) { }
150#endif
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) { }
153#endif
154#endif
155
156 static constexpr QChar fromUcs2(char16_t c) noexcept { return QChar{c}; }
157 [[nodiscard]] static constexpr inline auto fromUcs4(char32_t c) noexcept
158 {
159 struct R {
160 char16_t chars[2];
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(); }
165 };
166 return requiresSurrogates(c) ? R{{QChar::highSurrogate(c),
167 QChar::lowSurrogate(c)}} :
168 R{{char16_t(c), u'\0'}} ;
169 }
170
171 // Unicode information
172
173 enum Category
174 {
175 Mark_NonSpacing, // Mn
176 Mark_SpacingCombining, // Mc
177 Mark_Enclosing, // Me
178
179 Number_DecimalDigit, // Nd
180 Number_Letter, // Nl
181 Number_Other, // No
182
183 Separator_Space, // Zs
184 Separator_Line, // Zl
185 Separator_Paragraph, // Zp
186
187 Other_Control, // Cc
188 Other_Format, // Cf
189 Other_Surrogate, // Cs
190 Other_PrivateUse, // Co
191 Other_NotAssigned, // Cn
192
193 Letter_Uppercase, // Lu
194 Letter_Lowercase, // Ll
195 Letter_Titlecase, // Lt
196 Letter_Modifier, // Lm
197 Letter_Other, // Lo
198
199 Punctuation_Connector, // Pc
200 Punctuation_Dash, // Pd
201 Punctuation_Open, // Ps
202 Punctuation_Close, // Pe
203 Punctuation_InitialQuote, // Pi
204 Punctuation_FinalQuote, // Pf
205 Punctuation_Other, // Po
206
207 Symbol_Math, // Sm
208 Symbol_Currency, // Sc
209 Symbol_Modifier, // Sk
210 Symbol_Other // So
211 };
212
213 enum Script
214 {
215 Script_Unknown,
216 Script_Inherited,
217 Script_Common,
218
219 Script_Latin,
220 Script_Greek,
221 Script_Cyrillic,
222 Script_Armenian,
223 Script_Hebrew,
224 Script_Arabic,
225 Script_Syriac,
226 Script_Thaana,
227 Script_Devanagari,
228 Script_Bengali,
229 Script_Gurmukhi,
230 Script_Gujarati,
231 Script_Oriya,
232 Script_Tamil,
233 Script_Telugu,
234 Script_Kannada,
235 Script_Malayalam,
236 Script_Sinhala,
237 Script_Thai,
238 Script_Lao,
239 Script_Tibetan,
240 Script_Myanmar,
241 Script_Georgian,
242 Script_Hangul,
243 Script_Ethiopic,
244 Script_Cherokee,
245 Script_CanadianAboriginal,
246 Script_Ogham,
247 Script_Runic,
248 Script_Khmer,
249 Script_Mongolian,
250 Script_Hiragana,
251 Script_Katakana,
252 Script_Bopomofo,
253 Script_Han,
254 Script_Yi,
255 Script_OldItalic,
256 Script_Gothic,
257 Script_Deseret,
258 Script_Tagalog,
259 Script_Hanunoo,
260 Script_Buhid,
261 Script_Tagbanwa,
262 Script_Coptic,
263
264 // Unicode 4.0 additions
265 Script_Limbu,
266 Script_TaiLe,
267 Script_LinearB,
268 Script_Ugaritic,
269 Script_Shavian,
270 Script_Osmanya,
271 Script_Cypriot,
272 Script_Braille,
273
274 // Unicode 4.1 additions
275 Script_Buginese,
276 Script_NewTaiLue,
277 Script_Glagolitic,
278 Script_Tifinagh,
279 Script_SylotiNagri,
280 Script_OldPersian,
281 Script_Kharoshthi,
282
283 // Unicode 5.0 additions
284 Script_Balinese,
285 Script_Cuneiform,
286 Script_Phoenician,
287 Script_PhagsPa,
288 Script_Nko,
289
290 // Unicode 5.1 additions
291 Script_Sundanese,
292 Script_Lepcha,
293 Script_OlChiki,
294 Script_Vai,
295 Script_Saurashtra,
296 Script_KayahLi,
297 Script_Rejang,
298 Script_Lycian,
299 Script_Carian,
300 Script_Lydian,
301 Script_Cham,
302
303 // Unicode 5.2 additions
304 Script_TaiTham,
305 Script_TaiViet,
306 Script_Avestan,
307 Script_EgyptianHieroglyphs,
308 Script_Samaritan,
309 Script_Lisu,
310 Script_Bamum,
311 Script_Javanese,
312 Script_MeeteiMayek,
313 Script_ImperialAramaic,
314 Script_OldSouthArabian,
315 Script_InscriptionalParthian,
316 Script_InscriptionalPahlavi,
317 Script_OldTurkic,
318 Script_Kaithi,
319
320 // Unicode 6.0 additions
321 Script_Batak,
322 Script_Brahmi,
323 Script_Mandaic,
324
325 // Unicode 6.1 additions
326 Script_Chakma,
327 Script_MeroiticCursive,
328 Script_MeroiticHieroglyphs,
329 Script_Miao,
330 Script_Sharada,
331 Script_SoraSompeng,
332 Script_Takri,
333
334 // Unicode 7.0 additions
335 Script_CaucasianAlbanian,
336 Script_BassaVah,
337 Script_Duployan,
338 Script_Elbasan,
339 Script_Grantha,
340 Script_PahawhHmong,
341 Script_Khojki,
342 Script_LinearA,
343 Script_Mahajani,
344 Script_Manichaean,
345 Script_MendeKikakui,
346 Script_Modi,
347 Script_Mro,
348 Script_OldNorthArabian,
349 Script_Nabataean,
350 Script_Palmyrene,
351 Script_PauCinHau,
352 Script_OldPermic,
353 Script_PsalterPahlavi,
354 Script_Siddham,
355 Script_Khudawadi,
356 Script_Tirhuta,
357 Script_WarangCiti,
358
359 // Unicode 8.0 additions
360 Script_Ahom,
361 Script_AnatolianHieroglyphs,
362 Script_Hatran,
363 Script_Multani,
364 Script_OldHungarian,
365 Script_SignWriting,
366
367 // Unicode 9.0 additions
368 Script_Adlam,
369 Script_Bhaiksuki,
370 Script_Marchen,
371 Script_Newa,
372 Script_Osage,
373 Script_Tangut,
374
375 // Unicode 10.0 additions
376 Script_MasaramGondi,
377 Script_Nushu,
378 Script_Soyombo,
379 Script_ZanabazarSquare,
380
381 // Unicode 12.1 additions
382 Script_Dogra,
383 Script_GunjalaGondi,
384 Script_HanifiRohingya,
385 Script_Makasar,
386 Script_Medefaidrin,
387 Script_OldSogdian,
388 Script_Sogdian,
389 Script_Elymaic,
390 Script_Nandinagari,
391 Script_NyiakengPuachueHmong,
392 Script_Wancho,
393
394 // Unicode 13.0 additions
395 Script_Chorasmian,
396 Script_DivesAkuru,
397 Script_KhitanSmallScript,
398 Script_Yezidi,
399
400 // Unicode 14.0 additions
401 Script_CyproMinoan,
402 Script_OldUyghur,
403 Script_Tangsa,
404 Script_Toto,
405 Script_Vithkuqi,
406
407 // Unicode 15.0 additions
408 Script_Kawi,
409 Script_NagMundari,
410
411 // Unicode 16.0 additions
412 Script_Garay,
413 Script_GurungKhema,
414 Script_KiratRai,
415 Script_OlOnal,
416 Script_Sunuwar,
417 Script_Todhri,
418 Script_TuluTigalari,
419
420 // Unicode 17.0 additions
421 Script_Sidetic,
422 Script_TaiYo,
423 Script_TolongSiki,
424 Script_BeriaErfe,
425
426 ScriptCount
427 };
428
429 enum Direction
430 {
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
434 };
435
436 enum Decomposition
437 {
438 NoDecomposition,
439 Canonical,
440 Font,
441 NoBreak,
442 Initial,
443 Medial,
444 Final,
445 Isolated,
446 Circle,
447 Super,
448 Sub,
449 Vertical,
450 Wide,
451 Narrow,
452 Small,
453 Square,
454 Compat,
455 Fraction
456 };
457
458 enum JoiningType {
459 Joining_None,
460 Joining_Causing,
461 Joining_Dual,
462 Joining_Right,
463 Joining_Left,
464 Joining_Transparent
465 };
466
467 enum CombiningClass
468 {
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,
477
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,
486
487 Combining_DoubleBelow = 233,
488 Combining_DoubleAbove = 234,
489 Combining_IotaSubscript = 240
490 };
491
492 enum UnicodeVersion {
493 Unicode_Unassigned,
494 Unicode_1_1,
495 Unicode_2_0,
496 Unicode_2_1_2,
497 Unicode_3_0,
498 Unicode_3_1,
499 Unicode_3_2,
500 Unicode_4_0,
501 Unicode_4_1,
502 Unicode_5_0,
503 Unicode_5_1,
504 Unicode_5_2,
505 Unicode_6_0,
506 Unicode_6_1,
507 Unicode_6_2,
508 Unicode_6_3,
509 Unicode_7_0,
510 Unicode_8_0,
511 Unicode_9_0,
512 Unicode_10_0,
513 Unicode_11_0,
514 Unicode_12_0,
515 Unicode_12_1,
516 Unicode_13_0,
517 Unicode_14_0,
518 Unicode_15_0,
519 Unicode_15_1,
520 Unicode_16_0,
521 Unicode_17_0,
522 };
523
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)); }
528
529 QChar mirroredChar() const noexcept { return QChar(QChar::mirroredChar(char32_t(ucs))); }
530 bool hasMirrored() const noexcept { return QChar::hasMirrored(char32_t(ucs)); }
531
532 QString decomposition() const;
533 Decomposition decompositionTag() const noexcept { return QChar::decompositionTag(char32_t(ucs)); }
534
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))); }
540
541 Script script() const noexcept { return QChar::script(char32_t(ucs)); }
542
543 UnicodeVersion unicodeVersion() const noexcept { return QChar::unicodeVersion(char32_t(ucs)); }
544
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; }
548
549 static constexpr QChar fromLatin1(char c) noexcept { return QLatin1Char(c); }
550
551 constexpr inline bool isNull() const noexcept { return ucs == 0; }
552
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)); }
565
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)); }
570
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)); }
575
576 static constexpr inline bool isNonCharacter(char32_t ucs4) noexcept
577 {
578 return ucs4 >= 0xfdd0 && (ucs4 <= 0xfdef || (ucs4 & 0xfffe) == 0xfffe);
579 }
580 static constexpr inline bool isHighSurrogate(char32_t ucs4) noexcept
581 {
582 return (ucs4 & 0xfffffc00) == 0xd800; // 0xd800 + up to 1023 (0x3ff)
583 }
584 static constexpr inline bool isLowSurrogate(char32_t ucs4) noexcept
585 {
586 return (ucs4 & 0xfffffc00) == 0xdc00; // 0xdc00 + up to 1023 (0x3ff)
587 }
588 static constexpr inline bool isSurrogate(char32_t ucs4) noexcept
589 {
590 return (ucs4 - 0xd800u < 2048u);
591 }
592 static constexpr inline bool requiresSurrogates(char32_t ucs4) noexcept
593 {
594 return (ucs4 >= 0x10000);
595 }
596 static constexpr inline char32_t surrogateToUcs4(char16_t high, char16_t low) noexcept
597 {
598 // 0x010000 through 0x10ffff, provided params are actual high, low surrogates.
599 // 0x010000 + ((high - 0xd800) << 10) + (low - 0xdc00), optimized:
600 return (char32_t(high)<<10) + low - 0x35fdc00;
601 }
602 static constexpr inline char32_t surrogateToUcs4(QChar high, QChar low) noexcept
603 {
604 return surrogateToUcs4(high.ucs, low.ucs);
605 }
606 static constexpr inline char16_t highSurrogate(char32_t ucs4) noexcept
607 {
608 return char16_t((ucs4>>10) + 0xd7c0);
609 }
610 static constexpr inline char16_t lowSurrogate(char32_t ucs4) noexcept
611 {
612 return char16_t(ucs4%0x400 + 0xdc00);
613 }
614
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;
619
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;
622
623 static QString QT_CHAR_FASTCALL decomposition(char32_t ucs4);
624 Q_DECL_CONST_FUNCTION static Decomposition QT_CHAR_FASTCALL decompositionTag(char32_t ucs4) noexcept;
625
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;
631
632 Q_DECL_CONST_FUNCTION static Script QT_CHAR_FASTCALL script(char32_t ucs4) noexcept;
633
634 Q_DECL_CONST_FUNCTION static UnicodeVersion QT_CHAR_FASTCALL unicodeVersion(char32_t ucs4) noexcept;
635
636 Q_DECL_CONST_FUNCTION static UnicodeVersion QT_CHAR_FASTCALL currentUnicodeVersion() noexcept;
637
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
640 {
641 // note that [0x09..0x0d] + 0x85 are exceptional Cc-s and must be handled explicitly
642 return ucs4 == 0x20 || (ucs4 <= 0x0d && ucs4 >= 0x09)
643 || (ucs4 > 127 && (ucs4 == 0x85 || ucs4 == 0xa0 || QChar::isSpace_helper(ucs4)));
644 }
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
649 {
650 return (ucs4 >= 'A' && ucs4 <= 'z' && (ucs4 >= 'a' || ucs4 <= 'Z'))
651 || (ucs4 > 127 && QChar::isLetter_helper(ucs4));
652 }
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
656 {
657 return (ucs4 >= 'A' && ucs4 <= 'z' && (ucs4 >= 'a' || ucs4 <= 'Z'))
658 || (ucs4 >= '0' && ucs4 <= '9')
659 || (ucs4 > 127 && QChar::isLetterOrNumber_helper(ucs4));
660 }
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; }
669
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)
676
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)
683
684private:
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;
689
690 // defined in qstring.cpp, because we need to go via QUtf8StringView
691 static bool QT_CHAR_FASTCALL
692 Q_DECL_CONST_FUNCTION equal_helper(QChar lhs, const char *rhs) noexcept;
693 static int QT_CHAR_FASTCALL
694 Q_DECL_CONST_FUNCTION compare_helper(QChar lhs, const char *rhs) noexcept;
695
696#if !defined(QT_NO_CAST_FROM_ASCII) && !defined(QT_RESTRICTED_CAST_FROM_ASCII)
697 Q_WEAK_OVERLOAD
698 friend bool comparesEqual(const QChar &lhs, const char *rhs) noexcept
699 { return equal_helper(lhs, rhs); }
700 Q_WEAK_OVERLOAD
701 friend Qt::strong_ordering compareThreeWay(const QChar &lhs, const char *rhs) noexcept
702 {
703 const int res = compare_helper(lhs, rhs);
704 return Qt::compareThreeWay(res, 0);
705 }
706 Q_DECLARE_STRONGLY_ORDERED(QChar, const char *, Q_WEAK_OVERLOAD QT_ASCII_CAST_WARN)
707#endif // !defined(QT_NO_CAST_FROM_ASCII) && !defined(QT_RESTRICTED_CAST_FROM_ASCII)
708
709 char16_t ucs;
710};
711#undef QT_CHAR_FASTCALL
712
714
715namespace Qt {
716inline namespace Literals {
717inline namespace StringLiterals {
718
719constexpr inline QLatin1Char operator""_L1(char ch) noexcept
720{
721 return QLatin1Char(ch);
722}
723
724} // StringLiterals
725} // Literals
726} // Qt
727
728QT_END_NAMESPACE
729
730namespace std {
731template <>
733{
734 template <typename = void> // for transparent constexpr tracking
736 noexcept(noexcept(std::hash<char16_t>{}(u' ')))
737 {
738 return std::hash<char16_t>{}(c.unicode());
739 }
740};
741} // namespace std
742
743#endif // QCHAR_H
static constexpr unsigned short specialCaseMap[]
constexpr unsigned int MaxSpecialCaseLength
static constexpr unsigned short uc_ligature_map[]
static Q_DECL_CONST_FUNCTION Q_ALWAYS_INLINE const Properties * qGetProp(char32_t ucs4) noexcept
constexpr QLatin1Char operator""_L1(char ch) noexcept
Definition qchar.h:719
Definition qcompare.h:111
bool operator<(const UCS2SurrogatePair &ligature, char32_t u1)
Definition qchar.cpp:1891
static constexpr quint32 Hangul_VCount
Definition qchar.cpp:1404
static constexpr char32_t Hangul_SBase
Definition qchar.cpp:1399
static constexpr char32_t Hangul_VBase
Definition qchar.cpp:1401
bool operator<(ushort u1, const UCS2Pair &ligature)
Definition qchar.cpp:1877
#define FLAG(x)
Definition qchar.cpp:14
static constexpr quint32 Hangul_LCount
Definition qchar.cpp:1403
static char32_t ligatureHelper(char32_t u1, char32_t u2)
Definition qchar.cpp:1894
bool operator<(const UCS2Pair &ligature, ushort u1)
Definition qchar.cpp:1879
static void canonicalOrderHelper(QString *str, QChar::UnicodeVersion version, qsizetype from)
Definition qchar.cpp:1999
static constexpr char32_t Hangul_LBase
Definition qchar.cpp:1400
static constexpr char32_t Hangul_TBase
Definition qchar.cpp:1402
bool operator<(char32_t u1, const UCS2SurrogatePair &ligature)
Definition qchar.cpp:1889
bool operator<(const UCS2SurrogatePair &ligature1, const UCS2SurrogatePair &ligature2)
Definition qchar.cpp:1887
bool operator<(const UCS2Pair &ligature1, const UCS2Pair &ligature2)
Definition qchar.cpp:1875
static auto fullConvertCase(char32_t uc, QUnicodeTables::Case which) noexcept
Definition qchar.cpp:1562
static constexpr quint32 Hangul_NCount
Definition qchar.cpp:1406
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:1934
static char32_t foldCase(const char16_t *cur, const char16_t *start)
Definition qchar.cpp:1686
static constexpr quint32 Hangul_SCount
Definition qchar.cpp:1407
static bool normalizationQuickCheckHelper(QString *str, QString::NormalizationForm mode, qsizetype from, qsizetype *lastStable)
Definition qchar.cpp:2086
static QChar foldCase(QChar ch) noexcept
Definition qchar.cpp:1701
static constexpr quint32 Hangul_TCount
Definition qchar.cpp:1405
static char16_t foldCase(char16_t ch) noexcept
Definition qchar.cpp:1696
#define QT_CHAR_FASTCALL
Definition qchar.h:47
Q_DECLARE_TYPEINFO(QDateTime::Data, Q_RELOCATABLE_TYPE)
uint QT_FASTCALL fetch1Pixel< QPixelLayout::BPP1LSB >(const uchar *src, int index)
#define GET_LIGATURE_INDEX(ucs4)
#define GET_DECOMPOSITION_INDEX(ucs4)
#define UNICODE_DATA_VERSION
\inmodule QtCore \reentrant
Definition qchar.h:18
friend constexpr Qt::strong_ordering compareThreeWay(const QLatin1Char &lhs, const QLatin1Char &rhs) noexcept
Definition qchar.h:28
friend constexpr bool comparesEqual(const QLatin1Char &lhs, char rhs) noexcept
Definition qchar.h:32
constexpr char16_t unicode() const noexcept
Converts a Latin-1 character to an 16-bit-encoded Unicode representation of the character.
Definition qchar.h:22
friend constexpr Qt::strong_ordering compareThreeWay(const QLatin1Char &lhs, char rhs) noexcept
Definition qchar.h:35
friend constexpr bool comparesEqual(const QLatin1Char &lhs, const QLatin1Char &rhs) noexcept
Definition qchar.h:25
constexpr char toLatin1() const noexcept
Converts a Latin-1 character to an 8-bit ASCII representation of the character.
Definition qchar.h:21
constexpr QLatin1Char(char c) noexcept
Constructs a Latin-1 character for c.
Definition qchar.h:20
ushort u1
Definition qchar.cpp:1871
ushort u2
Definition qchar.cpp:1872