1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2020 The Qt Company Ltd. |
4 | ** Contact: https://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the QtCore module of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:LGPL$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and The Qt Company. For licensing terms |
14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at https://www.qt.io/contact-us. |
16 | ** |
17 | ** GNU Lesser General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
19 | ** General Public License version 3 as published by the Free Software |
20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the |
21 | ** packaging of this file. Please review the following information to |
22 | ** ensure the GNU Lesser General Public License version 3 requirements |
23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
24 | ** |
25 | ** GNU General Public License Usage |
26 | ** Alternatively, this file may be used under the terms of the GNU |
27 | ** General Public License version 2.0 or (at your option) the GNU General |
28 | ** Public license version 3 or any later version approved by the KDE Free |
29 | ** Qt Foundation. The licenses are as published by the Free Software |
30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
31 | ** included in the packaging of this file. Please review the following |
32 | ** information to ensure the GNU General Public License requirements will |
33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
34 | ** https://www.gnu.org/licenses/gpl-3.0.html. |
35 | ** |
36 | ** $QT_END_LICENSE$ |
37 | ** |
38 | ****************************************************************************/ |
39 | |
40 | #ifndef QCHAR_H |
41 | #define QCHAR_H |
42 | |
43 | #include <QtCore/qglobal.h> |
44 | |
45 | #include <functional> // for std::hash |
46 | |
47 | QT_BEGIN_NAMESPACE |
48 | |
49 | |
50 | class QString; |
51 | |
52 | struct QLatin1Char |
53 | { |
54 | public: |
55 | constexpr inline explicit QLatin1Char(char c) noexcept : ch(c) {} |
56 | constexpr inline char toLatin1() const noexcept { return ch; } |
57 | constexpr inline char16_t unicode() const noexcept { return char16_t(uchar(ch)); } |
58 | |
59 | friend constexpr inline bool operator==(QLatin1Char lhs, QLatin1Char rhs) noexcept { return lhs.ch == rhs.ch; } |
60 | friend constexpr inline bool operator!=(QLatin1Char lhs, QLatin1Char rhs) noexcept { return lhs.ch != rhs.ch; } |
61 | friend constexpr inline bool operator<=(QLatin1Char lhs, QLatin1Char rhs) noexcept { return lhs.ch <= rhs.ch; } |
62 | friend constexpr inline bool operator>=(QLatin1Char lhs, QLatin1Char rhs) noexcept { return lhs.ch >= rhs.ch; } |
63 | friend constexpr inline bool operator< (QLatin1Char lhs, QLatin1Char rhs) noexcept { return lhs.ch < rhs.ch; } |
64 | friend constexpr inline bool operator> (QLatin1Char lhs, QLatin1Char rhs) noexcept { return lhs.ch > rhs.ch; } |
65 | |
66 | friend constexpr inline bool operator==(char lhs, QLatin1Char rhs) noexcept { return lhs == rhs.toLatin1(); } |
67 | friend constexpr inline bool operator!=(char lhs, QLatin1Char rhs) noexcept { return lhs != rhs.toLatin1(); } |
68 | friend constexpr inline bool operator<=(char lhs, QLatin1Char rhs) noexcept { return lhs <= rhs.toLatin1(); } |
69 | friend constexpr inline bool operator>=(char lhs, QLatin1Char rhs) noexcept { return lhs >= rhs.toLatin1(); } |
70 | friend constexpr inline bool operator< (char lhs, QLatin1Char rhs) noexcept { return lhs < rhs.toLatin1(); } |
71 | friend constexpr inline bool operator> (char lhs, QLatin1Char rhs) noexcept { return lhs > rhs.toLatin1(); } |
72 | |
73 | friend constexpr inline bool operator==(QLatin1Char lhs, char rhs) noexcept { return lhs.toLatin1() == rhs; } |
74 | friend constexpr inline bool operator!=(QLatin1Char lhs, char rhs) noexcept { return lhs.toLatin1() != rhs; } |
75 | friend constexpr inline bool operator<=(QLatin1Char lhs, char rhs) noexcept { return lhs.toLatin1() <= rhs; } |
76 | friend constexpr inline bool operator>=(QLatin1Char lhs, char rhs) noexcept { return lhs.toLatin1() >= rhs; } |
77 | friend constexpr inline bool operator< (QLatin1Char lhs, char rhs) noexcept { return lhs.toLatin1() < rhs; } |
78 | friend constexpr inline bool operator> (QLatin1Char lhs, char rhs) noexcept { return lhs.toLatin1() > rhs; } |
79 | |
80 | private: |
81 | char ch; |
82 | }; |
83 | |
84 | class Q_CORE_EXPORT QChar { |
85 | public: |
86 | enum SpecialCharacter { |
87 | Null = 0x0000, |
88 | Tabulation = 0x0009, |
89 | LineFeed = 0x000a, |
90 | FormFeed = 0x000c, |
91 | CarriageReturn = 0x000d, |
92 | Space = 0x0020, |
93 | Nbsp = 0x00a0, |
94 | SoftHyphen = 0x00ad, |
95 | ReplacementCharacter = 0xfffd, |
96 | ObjectReplacementCharacter = 0xfffc, |
97 | ByteOrderMark = 0xfeff, |
98 | ByteOrderSwapped = 0xfffe, |
99 | ParagraphSeparator = 0x2029, |
100 | LineSeparator = 0x2028, |
101 | VisualTabCharacter = 0x2192, |
102 | LastValidCodePoint = 0x10ffff |
103 | }; |
104 | |
105 | #ifdef QT_IMPLICIT_QCHAR_CONSTRUCTION |
106 | #define QCHAR_MAYBE_IMPLICIT Q_IMPLICIT |
107 | #else |
108 | #define QCHAR_MAYBE_IMPLICIT explicit |
109 | #endif |
110 | |
111 | constexpr Q_IMPLICIT QChar() noexcept : ucs(0) {} |
112 | constexpr Q_IMPLICIT QChar(ushort rc) noexcept : ucs(rc) {} |
113 | constexpr QCHAR_MAYBE_IMPLICIT QChar(uchar c, uchar r) noexcept : ucs(char16_t((r << 8) | c)) {} |
114 | constexpr Q_IMPLICIT QChar(short rc) noexcept : ucs(char16_t(rc)) {} |
115 | constexpr QCHAR_MAYBE_IMPLICIT QChar(uint rc) noexcept : ucs((Q_ASSERT(rc <= 0xffff), char16_t(rc))) {} |
116 | constexpr QCHAR_MAYBE_IMPLICIT QChar(int rc) noexcept : QChar(uint(rc)) {} |
117 | constexpr Q_IMPLICIT QChar(SpecialCharacter s) noexcept : ucs(char16_t(s)) {} |
118 | constexpr Q_IMPLICIT QChar(QLatin1Char ch) noexcept : ucs(ch.unicode()) {} |
119 | constexpr Q_IMPLICIT QChar(char16_t ch) noexcept : ucs(ch) {} |
120 | #if defined(Q_OS_WIN) || defined(Q_CLANG_QDOC) |
121 | constexpr Q_IMPLICIT QChar(wchar_t ch) noexcept : ucs(char16_t(ch)) {} |
122 | #endif |
123 | |
124 | #ifndef QT_NO_CAST_FROM_ASCII |
125 | // Always implicit -- allow for 'x' => QChar conversions |
126 | QT_ASCII_CAST_WARN constexpr Q_IMPLICIT QChar(char c) noexcept : ucs(uchar(c)) { } |
127 | #ifndef QT_RESTRICTED_CAST_FROM_ASCII |
128 | QT_ASCII_CAST_WARN constexpr QCHAR_MAYBE_IMPLICIT QChar(uchar c) noexcept : ucs(c) { } |
129 | #endif |
130 | #endif |
131 | |
132 | #undef QCHAR_MAYBE_IMPLICIT |
133 | |
134 | static constexpr QChar fromUcs2(char16_t c) noexcept { return QChar{c}; } |
135 | static constexpr inline auto fromUcs4(char32_t c) noexcept; |
136 | |
137 | // Unicode information |
138 | |
139 | enum Category |
140 | { |
141 | Mark_NonSpacing, // Mn |
142 | Mark_SpacingCombining, // Mc |
143 | Mark_Enclosing, // Me |
144 | |
145 | Number_DecimalDigit, // Nd |
146 | Number_Letter, // Nl |
147 | Number_Other, // No |
148 | |
149 | Separator_Space, // Zs |
150 | Separator_Line, // Zl |
151 | Separator_Paragraph, // Zp |
152 | |
153 | Other_Control, // Cc |
154 | Other_Format, // Cf |
155 | Other_Surrogate, // Cs |
156 | Other_PrivateUse, // Co |
157 | Other_NotAssigned, // Cn |
158 | |
159 | Letter_Uppercase, // Lu |
160 | Letter_Lowercase, // Ll |
161 | Letter_Titlecase, // Lt |
162 | Letter_Modifier, // Lm |
163 | Letter_Other, // Lo |
164 | |
165 | Punctuation_Connector, // Pc |
166 | Punctuation_Dash, // Pd |
167 | Punctuation_Open, // Ps |
168 | Punctuation_Close, // Pe |
169 | Punctuation_InitialQuote, // Pi |
170 | Punctuation_FinalQuote, // Pf |
171 | Punctuation_Other, // Po |
172 | |
173 | Symbol_Math, // Sm |
174 | Symbol_Currency, // Sc |
175 | Symbol_Modifier, // Sk |
176 | Symbol_Other // So |
177 | }; |
178 | |
179 | enum Script |
180 | { |
181 | Script_Unknown, |
182 | Script_Inherited, |
183 | Script_Common, |
184 | |
185 | Script_Latin, |
186 | Script_Greek, |
187 | Script_Cyrillic, |
188 | Script_Armenian, |
189 | Script_Hebrew, |
190 | Script_Arabic, |
191 | Script_Syriac, |
192 | Script_Thaana, |
193 | Script_Devanagari, |
194 | Script_Bengali, |
195 | Script_Gurmukhi, |
196 | Script_Gujarati, |
197 | Script_Oriya, |
198 | Script_Tamil, |
199 | Script_Telugu, |
200 | Script_Kannada, |
201 | Script_Malayalam, |
202 | Script_Sinhala, |
203 | Script_Thai, |
204 | Script_Lao, |
205 | Script_Tibetan, |
206 | Script_Myanmar, |
207 | Script_Georgian, |
208 | Script_Hangul, |
209 | Script_Ethiopic, |
210 | Script_Cherokee, |
211 | Script_CanadianAboriginal, |
212 | Script_Ogham, |
213 | Script_Runic, |
214 | Script_Khmer, |
215 | Script_Mongolian, |
216 | Script_Hiragana, |
217 | Script_Katakana, |
218 | Script_Bopomofo, |
219 | Script_Han, |
220 | Script_Yi, |
221 | Script_OldItalic, |
222 | Script_Gothic, |
223 | Script_Deseret, |
224 | Script_Tagalog, |
225 | Script_Hanunoo, |
226 | Script_Buhid, |
227 | Script_Tagbanwa, |
228 | Script_Coptic, |
229 | |
230 | // Unicode 4.0 additions |
231 | Script_Limbu, |
232 | Script_TaiLe, |
233 | Script_LinearB, |
234 | Script_Ugaritic, |
235 | Script_Shavian, |
236 | Script_Osmanya, |
237 | Script_Cypriot, |
238 | Script_Braille, |
239 | |
240 | // Unicode 4.1 additions |
241 | Script_Buginese, |
242 | Script_NewTaiLue, |
243 | Script_Glagolitic, |
244 | Script_Tifinagh, |
245 | Script_SylotiNagri, |
246 | Script_OldPersian, |
247 | Script_Kharoshthi, |
248 | |
249 | // Unicode 5.0 additions |
250 | Script_Balinese, |
251 | Script_Cuneiform, |
252 | Script_Phoenician, |
253 | Script_PhagsPa, |
254 | Script_Nko, |
255 | |
256 | // Unicode 5.1 additions |
257 | Script_Sundanese, |
258 | Script_Lepcha, |
259 | Script_OlChiki, |
260 | Script_Vai, |
261 | Script_Saurashtra, |
262 | Script_KayahLi, |
263 | Script_Rejang, |
264 | Script_Lycian, |
265 | Script_Carian, |
266 | Script_Lydian, |
267 | Script_Cham, |
268 | |
269 | // Unicode 5.2 additions |
270 | Script_TaiTham, |
271 | Script_TaiViet, |
272 | Script_Avestan, |
273 | Script_EgyptianHieroglyphs, |
274 | Script_Samaritan, |
275 | Script_Lisu, |
276 | Script_Bamum, |
277 | Script_Javanese, |
278 | Script_MeeteiMayek, |
279 | Script_ImperialAramaic, |
280 | Script_OldSouthArabian, |
281 | Script_InscriptionalParthian, |
282 | Script_InscriptionalPahlavi, |
283 | Script_OldTurkic, |
284 | Script_Kaithi, |
285 | |
286 | // Unicode 6.0 additions |
287 | Script_Batak, |
288 | Script_Brahmi, |
289 | Script_Mandaic, |
290 | |
291 | // Unicode 6.1 additions |
292 | Script_Chakma, |
293 | Script_MeroiticCursive, |
294 | Script_MeroiticHieroglyphs, |
295 | Script_Miao, |
296 | Script_Sharada, |
297 | Script_SoraSompeng, |
298 | Script_Takri, |
299 | |
300 | // Unicode 7.0 additions |
301 | Script_CaucasianAlbanian, |
302 | Script_BassaVah, |
303 | Script_Duployan, |
304 | Script_Elbasan, |
305 | Script_Grantha, |
306 | Script_PahawhHmong, |
307 | Script_Khojki, |
308 | Script_LinearA, |
309 | Script_Mahajani, |
310 | Script_Manichaean, |
311 | Script_MendeKikakui, |
312 | Script_Modi, |
313 | Script_Mro, |
314 | Script_OldNorthArabian, |
315 | Script_Nabataean, |
316 | Script_Palmyrene, |
317 | Script_PauCinHau, |
318 | Script_OldPermic, |
319 | Script_PsalterPahlavi, |
320 | Script_Siddham, |
321 | Script_Khudawadi, |
322 | Script_Tirhuta, |
323 | Script_WarangCiti, |
324 | |
325 | // Unicode 8.0 additions |
326 | Script_Ahom, |
327 | Script_AnatolianHieroglyphs, |
328 | Script_Hatran, |
329 | Script_Multani, |
330 | Script_OldHungarian, |
331 | Script_SignWriting, |
332 | |
333 | // Unicode 9.0 additions |
334 | Script_Adlam, |
335 | Script_Bhaiksuki, |
336 | Script_Marchen, |
337 | Script_Newa, |
338 | Script_Osage, |
339 | Script_Tangut, |
340 | |
341 | // Unicode 10.0 additions |
342 | Script_MasaramGondi, |
343 | Script_Nushu, |
344 | Script_Soyombo, |
345 | Script_ZanabazarSquare, |
346 | |
347 | // Unicode 12.1 additions |
348 | Script_Dogra, |
349 | Script_GunjalaGondi, |
350 | Script_HanifiRohingya, |
351 | Script_Makasar, |
352 | Script_Medefaidrin, |
353 | Script_OldSogdian, |
354 | Script_Sogdian, |
355 | Script_Elymaic, |
356 | Script_Nandinagari, |
357 | Script_NyiakengPuachueHmong, |
358 | Script_Wancho, |
359 | |
360 | // Unicode 13.0 additions |
361 | Script_Chorasmian, |
362 | Script_DivesAkuru, |
363 | Script_KhitanSmallScript, |
364 | Script_Yezidi, |
365 | |
366 | ScriptCount |
367 | }; |
368 | |
369 | enum Direction |
370 | { |
371 | DirL, DirR, DirEN, DirES, DirET, DirAN, DirCS, DirB, DirS, DirWS, DirON, |
372 | DirLRE, DirLRO, DirAL, DirRLE, DirRLO, DirPDF, DirNSM, DirBN, |
373 | DirLRI, DirRLI, DirFSI, DirPDI |
374 | }; |
375 | |
376 | enum Decomposition |
377 | { |
378 | NoDecomposition, |
379 | Canonical, |
380 | Font, |
381 | NoBreak, |
382 | Initial, |
383 | Medial, |
384 | Final, |
385 | Isolated, |
386 | Circle, |
387 | Super, |
388 | Sub, |
389 | Vertical, |
390 | Wide, |
391 | Narrow, |
392 | Small, |
393 | Square, |
394 | Compat, |
395 | Fraction |
396 | }; |
397 | |
398 | enum JoiningType { |
399 | Joining_None, |
400 | Joining_Causing, |
401 | Joining_Dual, |
402 | Joining_Right, |
403 | Joining_Left, |
404 | Joining_Transparent |
405 | }; |
406 | |
407 | enum CombiningClass |
408 | { |
409 | Combining_BelowLeftAttached = 200, |
410 | Combining_BelowAttached = 202, |
411 | Combining_BelowRightAttached = 204, |
412 | Combining_LeftAttached = 208, |
413 | Combining_RightAttached = 210, |
414 | Combining_AboveLeftAttached = 212, |
415 | Combining_AboveAttached = 214, |
416 | Combining_AboveRightAttached = 216, |
417 | |
418 | Combining_BelowLeft = 218, |
419 | Combining_Below = 220, |
420 | Combining_BelowRight = 222, |
421 | Combining_Left = 224, |
422 | Combining_Right = 226, |
423 | Combining_AboveLeft = 228, |
424 | Combining_Above = 230, |
425 | Combining_AboveRight = 232, |
426 | |
427 | Combining_DoubleBelow = 233, |
428 | Combining_DoubleAbove = 234, |
429 | Combining_IotaSubscript = 240 |
430 | }; |
431 | |
432 | enum UnicodeVersion { |
433 | Unicode_Unassigned, |
434 | Unicode_1_1, |
435 | Unicode_2_0, |
436 | Unicode_2_1_2, |
437 | Unicode_3_0, |
438 | Unicode_3_1, |
439 | Unicode_3_2, |
440 | Unicode_4_0, |
441 | Unicode_4_1, |
442 | Unicode_5_0, |
443 | Unicode_5_1, |
444 | Unicode_5_2, |
445 | Unicode_6_0, |
446 | Unicode_6_1, |
447 | Unicode_6_2, |
448 | Unicode_6_3, |
449 | Unicode_7_0, |
450 | Unicode_8_0, |
451 | Unicode_9_0, |
452 | Unicode_10_0, |
453 | Unicode_11_0, |
454 | Unicode_12_0, |
455 | Unicode_12_1, |
456 | Unicode_13_0 |
457 | }; |
458 | |
459 | inline Category category() const noexcept { return QChar::category(ucs); } |
460 | inline Direction direction() const noexcept { return QChar::direction(ucs); } |
461 | inline JoiningType joiningType() const noexcept { return QChar::joiningType(ucs); } |
462 | inline unsigned char combiningClass() const noexcept { return QChar::combiningClass(ucs); } |
463 | |
464 | inline QChar mirroredChar() const noexcept { return QChar(QChar::mirroredChar(ucs)); } |
465 | inline bool hasMirrored() const noexcept { return QChar::hasMirrored(ucs); } |
466 | |
467 | QString decomposition() const; |
468 | inline Decomposition decompositionTag() const noexcept { return QChar::decompositionTag(ucs); } |
469 | |
470 | inline int digitValue() const noexcept { return QChar::digitValue(ucs); } |
471 | inline QChar toLower() const noexcept { return QChar(QChar::toLower(ucs)); } |
472 | inline QChar toUpper() const noexcept { return QChar(QChar::toUpper(ucs)); } |
473 | inline QChar toTitleCase() const noexcept { return QChar(QChar::toTitleCase(ucs)); } |
474 | inline QChar toCaseFolded() const noexcept { return QChar(QChar::toCaseFolded(ucs)); } |
475 | |
476 | inline Script script() const noexcept { return QChar::script(ucs); } |
477 | |
478 | inline UnicodeVersion unicodeVersion() const noexcept { return QChar::unicodeVersion(ucs); } |
479 | |
480 | constexpr inline char toLatin1() const noexcept { return ucs > 0xff ? '\0' : char(ucs); } |
481 | constexpr inline char16_t unicode() const noexcept { return ucs; } |
482 | constexpr inline char16_t &unicode() noexcept { return ucs; } |
483 | |
484 | static constexpr QChar fromLatin1(char c) noexcept { return QLatin1Char(c); } |
485 | |
486 | constexpr inline bool isNull() const noexcept { return ucs == 0; } |
487 | |
488 | inline bool isPrint() const noexcept { return QChar::isPrint(ucs); } |
489 | constexpr inline bool isSpace() const noexcept { return QChar::isSpace(ucs); } |
490 | inline bool isMark() const noexcept { return QChar::isMark(ucs); } |
491 | inline bool isPunct() const noexcept { return QChar::isPunct(ucs); } |
492 | inline bool isSymbol() const noexcept { return QChar::isSymbol(ucs); } |
493 | constexpr inline bool isLetter() const noexcept { return QChar::isLetter(ucs); } |
494 | constexpr inline bool isNumber() const noexcept { return QChar::isNumber(ucs); } |
495 | constexpr inline bool isLetterOrNumber() const noexcept { return QChar::isLetterOrNumber(ucs); } |
496 | constexpr inline bool isDigit() const noexcept { return QChar::isDigit(ucs); } |
497 | constexpr inline bool isLower() const noexcept { return QChar::isLower(ucs); } |
498 | constexpr inline bool isUpper() const noexcept { return QChar::isUpper(ucs); } |
499 | constexpr inline bool isTitleCase() const noexcept { return QChar::isTitleCase(ucs); } |
500 | |
501 | constexpr inline bool isNonCharacter() const noexcept { return QChar::isNonCharacter(ucs); } |
502 | constexpr inline bool isHighSurrogate() const noexcept { return QChar::isHighSurrogate(ucs); } |
503 | constexpr inline bool isLowSurrogate() const noexcept { return QChar::isLowSurrogate(ucs); } |
504 | constexpr inline bool isSurrogate() const noexcept { return QChar::isSurrogate(ucs); } |
505 | |
506 | constexpr inline uchar cell() const noexcept { return uchar(ucs & 0xff); } |
507 | constexpr inline uchar row() const noexcept { return uchar((ucs>>8)&0xff); } |
508 | constexpr inline void setCell(uchar acell) noexcept { ucs = char16_t((ucs & 0xff00) + acell); } |
509 | constexpr inline void setRow(uchar arow) noexcept { ucs = char16_t((char16_t(arow)<<8) + (ucs&0xff)); } |
510 | |
511 | static constexpr inline bool isNonCharacter(char32_t ucs4) noexcept |
512 | { |
513 | return ucs4 >= 0xfdd0 && (ucs4 <= 0xfdef || (ucs4 & 0xfffe) == 0xfffe); |
514 | } |
515 | static constexpr inline bool isHighSurrogate(char32_t ucs4) noexcept |
516 | { |
517 | return (ucs4 & 0xfffffc00) == 0xd800; // 0xd800 + up to 1023 (0x3ff) |
518 | } |
519 | static constexpr inline bool isLowSurrogate(char32_t ucs4) noexcept |
520 | { |
521 | return (ucs4 & 0xfffffc00) == 0xdc00; // 0xdc00 + up to 1023 (0x3ff) |
522 | } |
523 | static constexpr inline bool isSurrogate(char32_t ucs4) noexcept |
524 | { |
525 | return (ucs4 - 0xd800u < 2048u); |
526 | } |
527 | static constexpr inline bool requiresSurrogates(char32_t ucs4) noexcept |
528 | { |
529 | return (ucs4 >= 0x10000); |
530 | } |
531 | static constexpr inline char32_t surrogateToUcs4(char16_t high, char16_t low) noexcept |
532 | { |
533 | // 0x010000 through 0x10ffff, provided params are actual high, low surrogates. |
534 | // 0x010000 + ((high - 0xd800) << 10) + (low - 0xdc00), optimized: |
535 | return (char32_t(high)<<10) + low - 0x35fdc00; |
536 | } |
537 | static constexpr inline char32_t surrogateToUcs4(QChar high, QChar low) noexcept |
538 | { |
539 | return surrogateToUcs4(high.ucs, low.ucs); |
540 | } |
541 | static constexpr inline char16_t highSurrogate(char32_t ucs4) noexcept |
542 | { |
543 | return char16_t((ucs4>>10) + 0xd7c0); |
544 | } |
545 | static constexpr inline char16_t lowSurrogate(char32_t ucs4) noexcept |
546 | { |
547 | return char16_t(ucs4%0x400 + 0xdc00); |
548 | } |
549 | |
550 | static Category QT_FASTCALL category(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION; |
551 | static Direction QT_FASTCALL direction(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION; |
552 | static JoiningType QT_FASTCALL joiningType(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION; |
553 | static unsigned char QT_FASTCALL combiningClass(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION; |
554 | |
555 | static char32_t QT_FASTCALL mirroredChar(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION; |
556 | static bool QT_FASTCALL hasMirrored(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION; |
557 | |
558 | static QString QT_FASTCALL decomposition(char32_t ucs4); |
559 | static Decomposition QT_FASTCALL decompositionTag(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION; |
560 | |
561 | static int QT_FASTCALL digitValue(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION; |
562 | static char32_t QT_FASTCALL toLower(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION; |
563 | static char32_t QT_FASTCALL toUpper(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION; |
564 | static char32_t QT_FASTCALL toTitleCase(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION; |
565 | static char32_t QT_FASTCALL toCaseFolded(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION; |
566 | |
567 | static Script QT_FASTCALL script(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION; |
568 | |
569 | static UnicodeVersion QT_FASTCALL unicodeVersion(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION; |
570 | |
571 | static UnicodeVersion QT_FASTCALL currentUnicodeVersion() noexcept Q_DECL_CONST_FUNCTION; |
572 | |
573 | static bool QT_FASTCALL isPrint(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION; |
574 | static constexpr inline bool isSpace(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION |
575 | { |
576 | // note that [0x09..0x0d] + 0x85 are exceptional Cc-s and must be handled explicitly |
577 | return ucs4 == 0x20 || (ucs4 <= 0x0d && ucs4 >= 0x09) |
578 | || (ucs4 > 127 && (ucs4 == 0x85 || ucs4 == 0xa0 || QChar::isSpace_helper(ucs4))); |
579 | } |
580 | static bool QT_FASTCALL isMark(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION; |
581 | static bool QT_FASTCALL isPunct(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION; |
582 | static bool QT_FASTCALL isSymbol(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION; |
583 | static constexpr inline bool isLetter(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION |
584 | { |
585 | return (ucs4 >= 'A' && ucs4 <= 'z' && (ucs4 >= 'a' || ucs4 <= 'Z')) |
586 | || (ucs4 > 127 && QChar::isLetter_helper(ucs4)); |
587 | } |
588 | static constexpr inline bool isNumber(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION |
589 | { return (ucs4 <= '9' && ucs4 >= '0') || (ucs4 > 127 && QChar::isNumber_helper(ucs4)); } |
590 | static constexpr inline bool isLetterOrNumber(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION |
591 | { |
592 | return (ucs4 >= 'A' && ucs4 <= 'z' && (ucs4 >= 'a' || ucs4 <= 'Z')) |
593 | || (ucs4 >= '0' && ucs4 <= '9') |
594 | || (ucs4 > 127 && QChar::isLetterOrNumber_helper(ucs4)); |
595 | } |
596 | static constexpr inline bool isDigit(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION |
597 | { return (ucs4 <= '9' && ucs4 >= '0') || (ucs4 > 127 && QChar::category(ucs4) == Number_DecimalDigit); } |
598 | static constexpr inline bool isLower(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION |
599 | { return (ucs4 <= 'z' && ucs4 >= 'a') || (ucs4 > 127 && QChar::category(ucs4) == Letter_Lowercase); } |
600 | static constexpr inline bool isUpper(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION |
601 | { return (ucs4 <= 'Z' && ucs4 >= 'A') || (ucs4 > 127 && QChar::category(ucs4) == Letter_Uppercase); } |
602 | static constexpr inline bool isTitleCase(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION |
603 | { return ucs4 > 127 && QChar::category(ucs4) == Letter_Titlecase; } |
604 | |
605 | friend constexpr inline bool operator==(QChar c1, QChar c2) noexcept { return c1.ucs == c2.ucs; } |
606 | friend constexpr inline bool operator< (QChar c1, QChar c2) noexcept { return c1.ucs < c2.ucs; } |
607 | |
608 | friend constexpr inline bool operator!=(QChar c1, QChar c2) noexcept { return !operator==(c1, c2); } |
609 | friend constexpr inline bool operator>=(QChar c1, QChar c2) noexcept { return !operator< (c1, c2); } |
610 | friend constexpr inline bool operator> (QChar c1, QChar c2) noexcept { return operator< (c2, c1); } |
611 | friend constexpr inline bool operator<=(QChar c1, QChar c2) noexcept { return !operator< (c2, c1); } |
612 | |
613 | friend constexpr inline bool operator==(QChar lhs, std::nullptr_t) noexcept { return lhs.isNull(); } |
614 | friend constexpr inline bool operator< (QChar, std::nullptr_t) noexcept { return false; } |
615 | friend constexpr inline bool operator==(std::nullptr_t, QChar rhs) noexcept { return rhs.isNull(); } |
616 | friend constexpr inline bool operator< (std::nullptr_t, QChar rhs) noexcept { return !rhs.isNull(); } |
617 | |
618 | friend constexpr inline bool operator!=(QChar lhs, std::nullptr_t) noexcept { return !operator==(lhs, nullptr); } |
619 | friend constexpr inline bool operator>=(QChar lhs, std::nullptr_t) noexcept { return !operator< (lhs, nullptr); } |
620 | friend constexpr inline bool operator> (QChar lhs, std::nullptr_t) noexcept { return operator< (nullptr, lhs); } |
621 | friend constexpr inline bool operator<=(QChar lhs, std::nullptr_t) noexcept { return !operator< (nullptr, lhs); } |
622 | |
623 | friend constexpr inline bool operator!=(std::nullptr_t, QChar rhs) noexcept { return !operator==(nullptr, rhs); } |
624 | friend constexpr inline bool operator>=(std::nullptr_t, QChar rhs) noexcept { return !operator< (nullptr, rhs); } |
625 | friend constexpr inline bool operator> (std::nullptr_t, QChar rhs) noexcept { return operator< (rhs, nullptr); } |
626 | friend constexpr inline bool operator<=(std::nullptr_t, QChar rhs) noexcept { return !operator< (rhs, nullptr); } |
627 | |
628 | private: |
629 | static bool QT_FASTCALL isSpace_helper(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION; |
630 | static bool QT_FASTCALL isLetter_helper(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION; |
631 | static bool QT_FASTCALL isNumber_helper(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION; |
632 | static bool QT_FASTCALL isLetterOrNumber_helper(char32_t ucs4) noexcept Q_DECL_CONST_FUNCTION; |
633 | |
634 | #ifdef QT_NO_CAST_FROM_ASCII |
635 | QChar(char c) = delete; |
636 | QChar(uchar c) = delete; |
637 | #endif |
638 | |
639 | char16_t ucs; |
640 | }; |
641 | |
642 | Q_DECLARE_TYPEINFO(QChar, Q_RELOCATABLE_TYPE); |
643 | |
644 | #ifndef QT_NO_DATASTREAM |
645 | Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, QChar); |
646 | Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QChar &); |
647 | #endif |
648 | |
649 | QT_END_NAMESPACE |
650 | |
651 | namespace std { |
652 | template <> |
653 | struct hash<QT_PREPEND_NAMESPACE(QChar)> |
654 | { |
655 | template <typename = void> // for transparent constexpr tracking |
656 | constexpr size_t operator()(QT_PREPEND_NAMESPACE(QChar) c) const |
657 | noexcept(noexcept(std::hash<char16_t>{}(u' '))) |
658 | { |
659 | return std::hash<char16_t>{}(c.unicode()); |
660 | } |
661 | }; |
662 | } // namespace std |
663 | |
664 | #endif // QCHAR_H |
665 | |
666 | #include <QtCore/qstringview.h> // for QChar::fromUcs4() definition |
667 | |