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)); }
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 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))) {}
136
137#ifndef QT_NO_CAST_FROM_ASCII
138 // Always implicit -- allow for 'x' => QChar conversions
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)) { }
141#endif
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) { }
147#endif
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) { }
150#endif
151#endif
152
153 static constexpr QChar fromUcs2(char16_t c) noexcept { return QChar{c}; }
154 [[nodiscard]] static constexpr inline auto fromUcs4(char32_t c) noexcept
155 {
156 struct R {
157 char16_t chars[2];
158 [[nodiscard]] constexpr qsizetype size() const noexcept { return chars[1] ? 2 : 1; }
159 [[nodiscard]] constexpr const char16_t *data() const noexcept { return chars; }
160 [[nodiscard]] constexpr const char16_t *begin() const noexcept { return chars; }
161 [[nodiscard]] constexpr const char16_t *end() const noexcept { return begin() + size(); }
162 };
163 return requiresSurrogates(c) ? R{{QChar::highSurrogate(c),
164 QChar::lowSurrogate(c)}} :
165 R{{char16_t(c), u'\0'}} ;
166 }
167
168 // Unicode information
169
170 enum Category
171 {
172 Mark_NonSpacing, // Mn
173 Mark_SpacingCombining, // Mc
174 Mark_Enclosing, // Me
175
176 Number_DecimalDigit, // Nd
177 Number_Letter, // Nl
178 Number_Other, // No
179
180 Separator_Space, // Zs
181 Separator_Line, // Zl
182 Separator_Paragraph, // Zp
183
184 Other_Control, // Cc
185 Other_Format, // Cf
186 Other_Surrogate, // Cs
187 Other_PrivateUse, // Co
188 Other_NotAssigned, // Cn
189
190 Letter_Uppercase, // Lu
191 Letter_Lowercase, // Ll
192 Letter_Titlecase, // Lt
193 Letter_Modifier, // Lm
194 Letter_Other, // Lo
195
196 Punctuation_Connector, // Pc
197 Punctuation_Dash, // Pd
198 Punctuation_Open, // Ps
199 Punctuation_Close, // Pe
200 Punctuation_InitialQuote, // Pi
201 Punctuation_FinalQuote, // Pf
202 Punctuation_Other, // Po
203
204 Symbol_Math, // Sm
205 Symbol_Currency, // Sc
206 Symbol_Modifier, // Sk
207 Symbol_Other // So
208 };
209
210 enum Script
211 {
212 Script_Unknown,
213 Script_Inherited,
214 Script_Common,
215
216 Script_Latin,
217 Script_Greek,
218 Script_Cyrillic,
219 Script_Armenian,
220 Script_Hebrew,
221 Script_Arabic,
222 Script_Syriac,
223 Script_Thaana,
224 Script_Devanagari,
225 Script_Bengali,
226 Script_Gurmukhi,
227 Script_Gujarati,
228 Script_Oriya,
229 Script_Tamil,
230 Script_Telugu,
231 Script_Kannada,
232 Script_Malayalam,
233 Script_Sinhala,
234 Script_Thai,
235 Script_Lao,
236 Script_Tibetan,
237 Script_Myanmar,
238 Script_Georgian,
239 Script_Hangul,
240 Script_Ethiopic,
241 Script_Cherokee,
242 Script_CanadianAboriginal,
243 Script_Ogham,
244 Script_Runic,
245 Script_Khmer,
246 Script_Mongolian,
247 Script_Hiragana,
248 Script_Katakana,
249 Script_Bopomofo,
250 Script_Han,
251 Script_Yi,
252 Script_OldItalic,
253 Script_Gothic,
254 Script_Deseret,
255 Script_Tagalog,
256 Script_Hanunoo,
257 Script_Buhid,
258 Script_Tagbanwa,
259 Script_Coptic,
260
261 // Unicode 4.0 additions
262 Script_Limbu,
263 Script_TaiLe,
264 Script_LinearB,
265 Script_Ugaritic,
266 Script_Shavian,
267 Script_Osmanya,
268 Script_Cypriot,
269 Script_Braille,
270
271 // Unicode 4.1 additions
272 Script_Buginese,
273 Script_NewTaiLue,
274 Script_Glagolitic,
275 Script_Tifinagh,
276 Script_SylotiNagri,
277 Script_OldPersian,
278 Script_Kharoshthi,
279
280 // Unicode 5.0 additions
281 Script_Balinese,
282 Script_Cuneiform,
283 Script_Phoenician,
284 Script_PhagsPa,
285 Script_Nko,
286
287 // Unicode 5.1 additions
288 Script_Sundanese,
289 Script_Lepcha,
290 Script_OlChiki,
291 Script_Vai,
292 Script_Saurashtra,
293 Script_KayahLi,
294 Script_Rejang,
295 Script_Lycian,
296 Script_Carian,
297 Script_Lydian,
298 Script_Cham,
299
300 // Unicode 5.2 additions
301 Script_TaiTham,
302 Script_TaiViet,
303 Script_Avestan,
304 Script_EgyptianHieroglyphs,
305 Script_Samaritan,
306 Script_Lisu,
307 Script_Bamum,
308 Script_Javanese,
309 Script_MeeteiMayek,
310 Script_ImperialAramaic,
311 Script_OldSouthArabian,
312 Script_InscriptionalParthian,
313 Script_InscriptionalPahlavi,
314 Script_OldTurkic,
315 Script_Kaithi,
316
317 // Unicode 6.0 additions
318 Script_Batak,
319 Script_Brahmi,
320 Script_Mandaic,
321
322 // Unicode 6.1 additions
323 Script_Chakma,
324 Script_MeroiticCursive,
325 Script_MeroiticHieroglyphs,
326 Script_Miao,
327 Script_Sharada,
328 Script_SoraSompeng,
329 Script_Takri,
330
331 // Unicode 7.0 additions
332 Script_CaucasianAlbanian,
333 Script_BassaVah,
334 Script_Duployan,
335 Script_Elbasan,
336 Script_Grantha,
337 Script_PahawhHmong,
338 Script_Khojki,
339 Script_LinearA,
340 Script_Mahajani,
341 Script_Manichaean,
342 Script_MendeKikakui,
343 Script_Modi,
344 Script_Mro,
345 Script_OldNorthArabian,
346 Script_Nabataean,
347 Script_Palmyrene,
348 Script_PauCinHau,
349 Script_OldPermic,
350 Script_PsalterPahlavi,
351 Script_Siddham,
352 Script_Khudawadi,
353 Script_Tirhuta,
354 Script_WarangCiti,
355
356 // Unicode 8.0 additions
357 Script_Ahom,
358 Script_AnatolianHieroglyphs,
359 Script_Hatran,
360 Script_Multani,
361 Script_OldHungarian,
362 Script_SignWriting,
363
364 // Unicode 9.0 additions
365 Script_Adlam,
366 Script_Bhaiksuki,
367 Script_Marchen,
368 Script_Newa,
369 Script_Osage,
370 Script_Tangut,
371
372 // Unicode 10.0 additions
373 Script_MasaramGondi,
374 Script_Nushu,
375 Script_Soyombo,
376 Script_ZanabazarSquare,
377
378 // Unicode 12.1 additions
379 Script_Dogra,
380 Script_GunjalaGondi,
381 Script_HanifiRohingya,
382 Script_Makasar,
383 Script_Medefaidrin,
384 Script_OldSogdian,
385 Script_Sogdian,
386 Script_Elymaic,
387 Script_Nandinagari,
388 Script_NyiakengPuachueHmong,
389 Script_Wancho,
390
391 // Unicode 13.0 additions
392 Script_Chorasmian,
393 Script_DivesAkuru,
394 Script_KhitanSmallScript,
395 Script_Yezidi,
396
397 // Unicode 14.0 additions
398 Script_CyproMinoan,
399 Script_OldUyghur,
400 Script_Tangsa,
401 Script_Toto,
402 Script_Vithkuqi,
403
404 // Unicode 15.0 additions
405 Script_Kawi,
406 Script_NagMundari,
407
408 // Unicode 16.0 additions
409 Script_Garay,
410 Script_GurungKhema,
411 Script_KiratRai,
412 Script_OlOnal,
413 Script_Sunuwar,
414 Script_Todhri,
415 Script_TuluTigalari,
416
417 // Unicode 17.0 additions
418 Script_Sidetic,
419 Script_TaiYo,
420 Script_TolongSiki,
421 Script_BeriaErfe,
422
423 ScriptCount
424 };
425
426 enum Direction
427 {
428 DirL, DirR, DirEN, DirES, DirET, DirAN, DirCS, DirB, DirS, DirWS, DirON,
429 DirLRE, DirLRO, DirAL, DirRLE, DirRLO, DirPDF, DirNSM, DirBN,
430 DirLRI, DirRLI, DirFSI, DirPDI
431 };
432
433 enum Decomposition
434 {
435 NoDecomposition,
436 Canonical,
437 Font,
438 NoBreak,
439 Initial,
440 Medial,
441 Final,
442 Isolated,
443 Circle,
444 Super,
445 Sub,
446 Vertical,
447 Wide,
448 Narrow,
449 Small,
450 Square,
451 Compat,
452 Fraction
453 };
454
455 enum JoiningType {
456 Joining_None,
457 Joining_Causing,
458 Joining_Dual,
459 Joining_Right,
460 Joining_Left,
461 Joining_Transparent
462 };
463
464 enum CombiningClass
465 {
466 Combining_BelowLeftAttached = 200,
467 Combining_BelowAttached = 202,
468 Combining_BelowRightAttached = 204,
469 Combining_LeftAttached = 208,
470 Combining_RightAttached = 210,
471 Combining_AboveLeftAttached = 212,
472 Combining_AboveAttached = 214,
473 Combining_AboveRightAttached = 216,
474
475 Combining_BelowLeft = 218,
476 Combining_Below = 220,
477 Combining_BelowRight = 222,
478 Combining_Left = 224,
479 Combining_Right = 226,
480 Combining_AboveLeft = 228,
481 Combining_Above = 230,
482 Combining_AboveRight = 232,
483
484 Combining_DoubleBelow = 233,
485 Combining_DoubleAbove = 234,
486 Combining_IotaSubscript = 240
487 };
488
489 enum UnicodeVersion {
490 Unicode_Unassigned,
491 Unicode_1_1,
492 Unicode_2_0,
493 Unicode_2_1_2,
494 Unicode_3_0,
495 Unicode_3_1,
496 Unicode_3_2,
497 Unicode_4_0,
498 Unicode_4_1,
499 Unicode_5_0,
500 Unicode_5_1,
501 Unicode_5_2,
502 Unicode_6_0,
503 Unicode_6_1,
504 Unicode_6_2,
505 Unicode_6_3,
506 Unicode_7_0,
507 Unicode_8_0,
508 Unicode_9_0,
509 Unicode_10_0,
510 Unicode_11_0,
511 Unicode_12_0,
512 Unicode_12_1,
513 Unicode_13_0,
514 Unicode_14_0,
515 Unicode_15_0,
516 Unicode_15_1,
517 Unicode_16_0,
518 Unicode_17_0,
519 };
520
521 Category category() const noexcept { return QChar::category(char32_t(ucs)); }
522 Direction direction() const noexcept { return QChar::direction(char32_t(ucs)); }
523 JoiningType joiningType() const noexcept { return QChar::joiningType(char32_t(ucs)); }
524 unsigned char combiningClass() const noexcept { return QChar::combiningClass(char32_t(ucs)); }
525
526 QChar mirroredChar() const noexcept { return QChar(QChar::mirroredChar(char32_t(ucs))); }
527 bool hasMirrored() const noexcept { return QChar::hasMirrored(char32_t(ucs)); }
528
529 QString decomposition() const;
530 Decomposition decompositionTag() const noexcept { return QChar::decompositionTag(char32_t(ucs)); }
531
532 int digitValue() const noexcept { return QChar::digitValue(char32_t(ucs)); }
533 QChar toLower() const noexcept { return QChar(QChar::toLower(char32_t(ucs))); }
534 QChar toUpper() const noexcept { return QChar(QChar::toUpper(char32_t(ucs))); }
535 QChar toTitleCase() const noexcept { return QChar(QChar::toTitleCase(char32_t(ucs))); }
536 QChar toCaseFolded() const noexcept { return QChar(QChar::toCaseFolded(char32_t(ucs))); }
537
538 Script script() const noexcept { return QChar::script(char32_t(ucs)); }
539
540 UnicodeVersion unicodeVersion() const noexcept { return QChar::unicodeVersion(char32_t(ucs)); }
541
542 constexpr inline char toLatin1() const noexcept { return ucs > 0xff ? '\0' : char(ucs); }
543 constexpr inline char16_t unicode() const noexcept { return ucs; }
544 constexpr inline char16_t &unicode() noexcept { return ucs; }
545
546 static constexpr QChar fromLatin1(char c) noexcept { return QLatin1Char(c); }
547
548 constexpr inline bool isNull() const noexcept { return ucs == 0; }
549
550 bool isPrint() const noexcept { return QChar::isPrint(char32_t(ucs)); }
551 constexpr bool isSpace() const noexcept { return QChar::isSpace(char32_t(ucs)); }
552 bool isMark() const noexcept { return QChar::isMark(char32_t(ucs)); }
553 bool isPunct() const noexcept { return QChar::isPunct(char32_t(ucs)); }
554 bool isSymbol() const noexcept { return QChar::isSymbol(char32_t(ucs)); }
555 constexpr bool isLetter() const noexcept { return QChar::isLetter(char32_t(ucs)); }
556 constexpr bool isNumber() const noexcept { return QChar::isNumber(char32_t(ucs)); }
557 constexpr bool isLetterOrNumber() const noexcept { return QChar::isLetterOrNumber(char32_t(ucs)); }
558 constexpr bool isDigit() const noexcept { return QChar::isDigit(char32_t(ucs)); }
559 constexpr bool isLower() const noexcept { return QChar::isLower(char32_t(ucs)); }
560 constexpr bool isUpper() const noexcept { return QChar::isUpper(char32_t(ucs)); }
561 constexpr bool isTitleCase() const noexcept { return QChar::isTitleCase(char32_t(ucs)); }
562
563 constexpr bool isNonCharacter() const noexcept { return QChar::isNonCharacter(char32_t(ucs)); }
564 constexpr bool isHighSurrogate() const noexcept { return QChar::isHighSurrogate(char32_t(ucs)); }
565 constexpr bool isLowSurrogate() const noexcept { return QChar::isLowSurrogate(char32_t(ucs)); }
566 constexpr bool isSurrogate() const noexcept { return QChar::isSurrogate(char32_t(ucs)); }
567
568 constexpr inline uchar cell() const noexcept { return uchar(ucs & 0xff); }
569 constexpr inline uchar row() const noexcept { return uchar((ucs>>8)&0xff); }
570 constexpr inline void setCell(uchar acell) noexcept { ucs = char16_t((ucs & 0xff00) + acell); }
571 constexpr inline void setRow(uchar arow) noexcept { ucs = char16_t((char16_t(arow)<<8) + (ucs&0xff)); }
572
573 static constexpr inline bool isNonCharacter(char32_t ucs4) noexcept
574 {
575 return ucs4 >= 0xfdd0 && (ucs4 <= 0xfdef || (ucs4 & 0xfffe) == 0xfffe);
576 }
577 static constexpr inline bool isHighSurrogate(char32_t ucs4) noexcept
578 {
579 return (ucs4 & 0xfffffc00) == 0xd800; // 0xd800 + up to 1023 (0x3ff)
580 }
581 static constexpr inline bool isLowSurrogate(char32_t ucs4) noexcept
582 {
583 return (ucs4 & 0xfffffc00) == 0xdc00; // 0xdc00 + up to 1023 (0x3ff)
584 }
585 static constexpr inline bool isSurrogate(char32_t ucs4) noexcept
586 {
587 return (ucs4 - 0xd800u < 2048u);
588 }
589 static constexpr inline bool requiresSurrogates(char32_t ucs4) noexcept
590 {
591 return (ucs4 >= 0x10000);
592 }
593 static constexpr inline char32_t surrogateToUcs4(char16_t high, char16_t low) noexcept
594 {
595 // 0x010000 through 0x10ffff, provided params are actual high, low surrogates.
596 // 0x010000 + ((high - 0xd800) << 10) + (low - 0xdc00), optimized:
597 return (char32_t(high)<<10) + low - 0x35fdc00;
598 }
599 static constexpr inline char32_t surrogateToUcs4(QChar high, QChar low) noexcept
600 {
601 return surrogateToUcs4(high.ucs, low.ucs);
602 }
603 static constexpr inline char16_t highSurrogate(char32_t ucs4) noexcept
604 {
605 return char16_t((ucs4>>10) + 0xd7c0);
606 }
607 static constexpr inline char16_t lowSurrogate(char32_t ucs4) noexcept
608 {
609 return char16_t(ucs4%0x400 + 0xdc00);
610 }
611
612 Q_DECL_CONST_FUNCTION static Category QT_CHAR_FASTCALL category(char32_t ucs4) noexcept;
613 Q_DECL_CONST_FUNCTION static Direction QT_CHAR_FASTCALL direction(char32_t ucs4) noexcept;
614 Q_DECL_CONST_FUNCTION static JoiningType QT_CHAR_FASTCALL joiningType(char32_t ucs4) noexcept;
615 Q_DECL_CONST_FUNCTION static unsigned char QT_CHAR_FASTCALL combiningClass(char32_t ucs4) noexcept;
616
617 Q_DECL_CONST_FUNCTION static char32_t QT_CHAR_FASTCALL mirroredChar(char32_t ucs4) noexcept;
618 Q_DECL_CONST_FUNCTION static bool QT_CHAR_FASTCALL hasMirrored(char32_t ucs4) noexcept;
619
620 static QString QT_CHAR_FASTCALL decomposition(char32_t ucs4);
621 Q_DECL_CONST_FUNCTION static Decomposition QT_CHAR_FASTCALL decompositionTag(char32_t ucs4) noexcept;
622
623 Q_DECL_CONST_FUNCTION static int QT_CHAR_FASTCALL digitValue(char32_t ucs4) noexcept;
624 Q_DECL_CONST_FUNCTION static char32_t QT_CHAR_FASTCALL toLower(char32_t ucs4) noexcept;
625 Q_DECL_CONST_FUNCTION static char32_t QT_CHAR_FASTCALL toUpper(char32_t ucs4) noexcept;
626 Q_DECL_CONST_FUNCTION static char32_t QT_CHAR_FASTCALL toTitleCase(char32_t ucs4) noexcept;
627 Q_DECL_CONST_FUNCTION static char32_t QT_CHAR_FASTCALL toCaseFolded(char32_t ucs4) noexcept;
628
629 Q_DECL_CONST_FUNCTION static Script QT_CHAR_FASTCALL script(char32_t ucs4) noexcept;
630
631 Q_DECL_CONST_FUNCTION static UnicodeVersion QT_CHAR_FASTCALL unicodeVersion(char32_t ucs4) noexcept;
632
633 Q_DECL_CONST_FUNCTION static UnicodeVersion QT_CHAR_FASTCALL currentUnicodeVersion() noexcept;
634
635 Q_DECL_CONST_FUNCTION static bool QT_CHAR_FASTCALL isPrint(char32_t ucs4) noexcept;
636 Q_DECL_CONST_FUNCTION static constexpr inline bool isSpace(char32_t ucs4) noexcept
637 {
638 // note that [0x09..0x0d] + 0x85 are exceptional Cc-s and must be handled explicitly
639 return ucs4 == 0x20 || (ucs4 <= 0x0d && ucs4 >= 0x09)
640 || (ucs4 > 127 && (ucs4 == 0x85 || ucs4 == 0xa0 || QChar::isSpace_helper(ucs4)));
641 }
642 Q_DECL_CONST_FUNCTION static bool QT_CHAR_FASTCALL isMark(char32_t ucs4) noexcept;
643 Q_DECL_CONST_FUNCTION static bool QT_CHAR_FASTCALL isPunct(char32_t ucs4) noexcept;
644 Q_DECL_CONST_FUNCTION static bool QT_CHAR_FASTCALL isSymbol(char32_t ucs4) noexcept;
645 Q_DECL_CONST_FUNCTION static constexpr inline bool isLetter(char32_t ucs4) noexcept
646 {
647 return (ucs4 >= 'A' && ucs4 <= 'z' && (ucs4 >= 'a' || ucs4 <= 'Z'))
648 || (ucs4 > 127 && QChar::isLetter_helper(ucs4));
649 }
650 Q_DECL_CONST_FUNCTION static constexpr inline bool isNumber(char32_t ucs4) noexcept
651 { return (ucs4 <= '9' && ucs4 >= '0') || (ucs4 > 127 && QChar::isNumber_helper(ucs4)); }
652 Q_DECL_CONST_FUNCTION static constexpr inline bool isLetterOrNumber(char32_t ucs4) noexcept
653 {
654 return (ucs4 >= 'A' && ucs4 <= 'z' && (ucs4 >= 'a' || ucs4 <= 'Z'))
655 || (ucs4 >= '0' && ucs4 <= '9')
656 || (ucs4 > 127 && QChar::isLetterOrNumber_helper(ucs4));
657 }
658 Q_DECL_CONST_FUNCTION static constexpr inline bool isDigit(char32_t ucs4) noexcept
659 { return (ucs4 <= '9' && ucs4 >= '0') || (ucs4 > 127 && QChar::category(ucs4) == Number_DecimalDigit); }
660 Q_DECL_CONST_FUNCTION static constexpr inline bool isLower(char32_t ucs4) noexcept
661 { return (ucs4 <= 'z' && ucs4 >= 'a') || (ucs4 > 127 && QChar::category(ucs4) == Letter_Lowercase); }
662 Q_DECL_CONST_FUNCTION static constexpr inline bool isUpper(char32_t ucs4) noexcept
663 { return (ucs4 <= 'Z' && ucs4 >= 'A') || (ucs4 > 127 && QChar::category(ucs4) == Letter_Uppercase); }
664 Q_DECL_CONST_FUNCTION static constexpr inline bool isTitleCase(char32_t ucs4) noexcept
665 { return ucs4 > 127 && QChar::category(ucs4) == Letter_Titlecase; }
666
667 friend constexpr bool comparesEqual(const QChar &lhs, const QChar &rhs) noexcept
668 { return lhs.ucs == rhs.ucs; }
669 friend constexpr Qt::strong_ordering
670 compareThreeWay(const QChar &lhs, const QChar &rhs) noexcept
671 { return Qt::compareThreeWay(lhs.ucs, rhs.ucs); }
672 Q_DECLARE_STRONGLY_ORDERED_LITERAL_TYPE(QChar)
673
674 friend constexpr bool comparesEqual(const QChar &lhs, std::nullptr_t) noexcept
675 { return lhs.isNull(); }
676 friend constexpr Qt::strong_ordering
677 compareThreeWay(const QChar &lhs, std::nullptr_t) noexcept
678 { return lhs.isNull() ? Qt::strong_ordering::equivalent : Qt::strong_ordering::greater; }
679 Q_DECLARE_STRONGLY_ORDERED_LITERAL_TYPE(QChar, std::nullptr_t)
680
681private:
682 Q_DECL_CONST_FUNCTION static bool QT_CHAR_FASTCALL isSpace_helper(char32_t ucs4) noexcept;
683 Q_DECL_CONST_FUNCTION static bool QT_CHAR_FASTCALL isLetter_helper(char32_t ucs4) noexcept;
684 Q_DECL_CONST_FUNCTION static bool QT_CHAR_FASTCALL isNumber_helper(char32_t ucs4) noexcept;
685 Q_DECL_CONST_FUNCTION static bool QT_CHAR_FASTCALL isLetterOrNumber_helper(char32_t ucs4) noexcept;
686
687 // defined in qstring.cpp, because we need to go via QUtf8StringView
688 static bool QT_CHAR_FASTCALL
689 Q_DECL_CONST_FUNCTION equal_helper(QChar lhs, const char *rhs) noexcept;
690 static int QT_CHAR_FASTCALL
691 Q_DECL_CONST_FUNCTION compare_helper(QChar lhs, const char *rhs) noexcept;
692
693#if !defined(QT_NO_CAST_FROM_ASCII) && !defined(QT_RESTRICTED_CAST_FROM_ASCII)
694 Q_WEAK_OVERLOAD
695 friend bool comparesEqual(const QChar &lhs, const char *rhs) noexcept
696 { return equal_helper(lhs, rhs); }
697 Q_WEAK_OVERLOAD
698 friend Qt::strong_ordering compareThreeWay(const QChar &lhs, const char *rhs) noexcept
699 {
700 const int res = compare_helper(lhs, rhs);
701 return Qt::compareThreeWay(res, 0);
702 }
703 Q_DECLARE_STRONGLY_ORDERED(QChar, const char *, Q_WEAK_OVERLOAD QT_ASCII_CAST_WARN)
704#endif // !defined(QT_NO_CAST_FROM_ASCII) && !defined(QT_RESTRICTED_CAST_FROM_ASCII)
705
706 char16_t ucs;
707};
708#undef QT_CHAR_FASTCALL
709
711
712namespace Qt {
713inline namespace Literals {
714inline namespace StringLiterals {
715
716constexpr inline QLatin1Char operator""_L1(char ch) noexcept
717{
718 return QLatin1Char(ch);
719}
720
721} // StringLiterals
722} // Literals
723} // Qt
724
725QT_END_NAMESPACE
726
727namespace std {
728template <>
730{
731 template <typename = void> // for transparent constexpr tracking
733 noexcept(noexcept(std::hash<char16_t>{}(u' ')))
734 {
735 return std::hash<char16_t>{}(c.unicode());
736 }
737};
738} // namespace std
739
740#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:716
Definition qcompare.h:110
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
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:18
friend constexpr Qt::strong_ordering compareThreeWay(const QLatin1Char &lhs, const QLatin1Char &rhs) noexcept
Definition qchar.h:28
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 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