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