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