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