1/****************************************************************************
2**
3** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4** Contact: http://www.qt-project.org/legal
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 Digia. For licensing terms and
14** conditions see http://qt.digia.com/licensing. For further information
15** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 2.1 requirements
23** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24**
25** In addition, as a special exception, Digia gives you certain additional
26** rights. These rights are described in the Digia Qt LGPL Exception
27** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28**
29** GNU General Public License Usage
30** Alternatively, this file may be used under the terms of the GNU
31** General Public License version 3.0 as published by the Free Software
32** Foundation and appearing in the file LICENSE.GPL included in the
33** packaging of this file. Please review the following information to
34** ensure the GNU General Public License version 3.0 requirements will be
35** met: http://www.gnu.org/copyleft/gpl.html.
36**
37**
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#ifndef QCHAR_H
43#define QCHAR_H
44
45#include <QtCore/qglobal.h>
46
47QT_BEGIN_HEADER
48
49QT_BEGIN_NAMESPACE
50
51QT_MODULE(Core)
52
53class QString;
54
55struct QLatin1Char
56{
57public:
58 inline explicit QLatin1Char(char c) : ch(c) {}
59#ifdef Q_COMPILER_MANGLES_RETURN_TYPE
60 inline const char toLatin1() const { return ch; }
61 inline const ushort unicode() const { return ushort(uchar(ch)); }
62#else
63 inline char toLatin1() const { return ch; }
64 inline ushort unicode() const { return ushort(uchar(ch)); }
65#endif
66
67private:
68 char ch;
69};
70
71
72class Q_CORE_EXPORT QChar {
73public:
74 QChar();
75#ifndef QT_NO_CAST_FROM_ASCII
76 QT_ASCII_CAST_WARN_CONSTRUCTOR QChar(char c);
77 QT_ASCII_CAST_WARN_CONSTRUCTOR QChar(uchar c);
78#endif
79 QChar(QLatin1Char ch);
80 QChar(uchar c, uchar r);
81 inline QChar(ushort rc) : ucs(rc){}
82 QChar(short rc);
83 QChar(uint rc);
84 QChar(int rc);
85 enum SpecialCharacter {
86 Null = 0x0000,
87 Nbsp = 0x00a0,
88 ReplacementCharacter = 0xfffd,
89 ObjectReplacementCharacter = 0xfffc,
90 ByteOrderMark = 0xfeff,
91 ByteOrderSwapped = 0xfffe,
92#ifdef QT3_SUPPORT
93 null = Null,
94 replacement = ReplacementCharacter,
95 byteOrderMark = ByteOrderMark,
96 byteOrderSwapped = ByteOrderSwapped,
97 nbsp = Nbsp,
98#endif
99 ParagraphSeparator = 0x2029,
100 LineSeparator = 0x2028
101 };
102 QChar(SpecialCharacter sc);
103
104 // Unicode information
105
106 enum Category
107 {
108 NoCategory, // ### Qt 5: replace with Other_NotAssigned
109
110 Mark_NonSpacing, // Mn
111 Mark_SpacingCombining, // Mc
112 Mark_Enclosing, // Me
113
114 Number_DecimalDigit, // Nd
115 Number_Letter, // Nl
116 Number_Other, // No
117
118 Separator_Space, // Zs
119 Separator_Line, // Zl
120 Separator_Paragraph, // Zp
121
122 Other_Control, // Cc
123 Other_Format, // Cf
124 Other_Surrogate, // Cs
125 Other_PrivateUse, // Co
126 Other_NotAssigned, // Cn
127
128 Letter_Uppercase, // Lu
129 Letter_Lowercase, // Ll
130 Letter_Titlecase, // Lt
131 Letter_Modifier, // Lm
132 Letter_Other, // Lo
133
134 Punctuation_Connector, // Pc
135 Punctuation_Dash, // Pd
136 Punctuation_Open, // Ps
137 Punctuation_Close, // Pe
138 Punctuation_InitialQuote, // Pi
139 Punctuation_FinalQuote, // Pf
140 Punctuation_Other, // Po
141
142 Symbol_Math, // Sm
143 Symbol_Currency, // Sc
144 Symbol_Modifier, // Sk
145 Symbol_Other, // So
146
147 Punctuation_Dask = Punctuation_Dash // ### Qt 5: remove
148 };
149
150 enum Direction
151 {
152 DirL, DirR, DirEN, DirES, DirET, DirAN, DirCS, DirB, DirS, DirWS, DirON,
153 DirLRE, DirLRO, DirAL, DirRLE, DirRLO, DirPDF, DirNSM, DirBN
154 };
155
156 enum Decomposition
157 {
158 NoDecomposition,
159 Canonical,
160 Font,
161 NoBreak,
162 Initial,
163 Medial,
164 Final,
165 Isolated,
166 Circle,
167 Super,
168 Sub,
169 Vertical,
170 Wide,
171 Narrow,
172 Small,
173 Square,
174 Compat,
175 Fraction
176
177#ifdef QT3_SUPPORT
178 , Single = NoDecomposition
179#endif
180 };
181
182 enum Joining
183 {
184 OtherJoining, Dual, Right, Center
185 };
186
187 enum CombiningClass
188 {
189 Combining_BelowLeftAttached = 200,
190 Combining_BelowAttached = 202,
191 Combining_BelowRightAttached = 204,
192 Combining_LeftAttached = 208,
193 Combining_RightAttached = 210,
194 Combining_AboveLeftAttached = 212,
195 Combining_AboveAttached = 214,
196 Combining_AboveRightAttached = 216,
197
198 Combining_BelowLeft = 218,
199 Combining_Below = 220,
200 Combining_BelowRight = 222,
201 Combining_Left = 224,
202 Combining_Right = 226,
203 Combining_AboveLeft = 228,
204 Combining_Above = 230,
205 Combining_AboveRight = 232,
206
207 Combining_DoubleBelow = 233,
208 Combining_DoubleAbove = 234,
209 Combining_IotaSubscript = 240
210 };
211
212 enum UnicodeVersion {
213 Unicode_Unassigned, // ### Qt 5: assign with some constantly big value
214 Unicode_1_1,
215 Unicode_2_0,
216 Unicode_2_1_2,
217 Unicode_3_0,
218 Unicode_3_1,
219 Unicode_3_2,
220 Unicode_4_0,
221 Unicode_4_1,
222 Unicode_5_0
223 };
224 // ****** WHEN ADDING FUNCTIONS, CONSIDER ADDING TO QCharRef TOO
225
226 Category category() const;
227 Direction direction() const;
228 Joining joining() const;
229 bool hasMirrored() const;
230 unsigned char combiningClass() const;
231
232 QChar mirroredChar() const;
233 QString decomposition() const;
234 Decomposition decompositionTag() const;
235
236 int digitValue() const;
237 QChar toLower() const;
238 QChar toUpper() const;
239 QChar toTitleCase() const;
240 QChar toCaseFolded() const;
241
242 UnicodeVersion unicodeVersion() const;
243
244#ifdef Q_COMPILER_MANGLES_RETURN_TYPE
245 const char toAscii() const;
246 inline const char toLatin1() const;
247 inline const ushort unicode() const { return ucs; }
248#else
249 char toAscii() const;
250 inline char toLatin1() const;
251 inline ushort unicode() const { return ucs; }
252#endif
253#ifdef Q_NO_PACKED_REFERENCE
254 inline ushort &unicode() { return const_cast<ushort&>(ucs); }
255#else
256 inline ushort &unicode() { return ucs; }
257#endif
258
259 static QChar fromAscii(char c);
260 static QChar fromLatin1(char c);
261
262 inline bool isNull() const { return ucs == 0; }
263 bool isPrint() const;
264 bool isPunct() const;
265 bool isSpace() const;
266 bool isMark() const;
267 bool isLetter() const;
268 bool isNumber() const;
269 bool isLetterOrNumber() const;
270 bool isDigit() const;
271 bool isSymbol() const;
272 inline bool isLower() const { return category() == Letter_Lowercase; }
273 inline bool isUpper() const { return category() == Letter_Uppercase; }
274 inline bool isTitleCase() const { return category() == Letter_Titlecase; }
275
276 inline bool isHighSurrogate() const {
277 return ((ucs & 0xfc00) == 0xd800);
278 }
279 inline bool isLowSurrogate() const {
280 return ((ucs & 0xfc00) == 0xdc00);
281 }
282
283 inline uchar cell() const { return uchar(ucs & 0xff); }
284 inline uchar row() const { return uchar((ucs>>8)&0xff); }
285 inline void setCell(uchar cell);
286 inline void setRow(uchar row);
287
288 static inline bool isHighSurrogate(uint ucs4) {
289 return ((ucs4 & 0xfffffc00) == 0xd800);
290 }
291 static inline bool isLowSurrogate(uint ucs4) {
292 return ((ucs4 & 0xfffffc00) == 0xdc00);
293 }
294 static inline bool requiresSurrogates(uint ucs4) {
295 return (ucs4 >= 0x10000);
296 }
297 static inline uint surrogateToUcs4(ushort high, ushort low) {
298 return (uint(high)<<10) + low - 0x35fdc00;
299 }
300 static inline uint surrogateToUcs4(QChar high, QChar low) {
301 return (uint(high.ucs)<<10) + low.ucs - 0x35fdc00;
302 }
303 static inline ushort highSurrogate(uint ucs4) {
304 return ushort((ucs4>>10) + 0xd7c0);
305 }
306 static inline ushort lowSurrogate(uint ucs4) {
307 return ushort(ucs4%0x400 + 0xdc00);
308 }
309
310 static Category QT_FASTCALL category(uint ucs4);
311 static Category QT_FASTCALL category(ushort ucs2);
312 static Direction QT_FASTCALL direction(uint ucs4);
313 static Direction QT_FASTCALL direction(ushort ucs2);
314 static Joining QT_FASTCALL joining(uint ucs4);
315 static Joining QT_FASTCALL joining(ushort ucs2);
316 static unsigned char QT_FASTCALL combiningClass(uint ucs4);
317 static unsigned char QT_FASTCALL combiningClass(ushort ucs2);
318
319 static uint QT_FASTCALL mirroredChar(uint ucs4);
320 static ushort QT_FASTCALL mirroredChar(ushort ucs2);
321 static Decomposition QT_FASTCALL decompositionTag(uint ucs4);
322
323 static int QT_FASTCALL digitValue(uint ucs4);
324 static int QT_FASTCALL digitValue(ushort ucs2);
325 static uint QT_FASTCALL toLower(uint ucs4);
326 static ushort QT_FASTCALL toLower(ushort ucs2);
327 static uint QT_FASTCALL toUpper(uint ucs4);
328 static ushort QT_FASTCALL toUpper(ushort ucs2);
329 static uint QT_FASTCALL toTitleCase(uint ucs4);
330 static ushort QT_FASTCALL toTitleCase(ushort ucs2);
331 static uint QT_FASTCALL toCaseFolded(uint ucs4);
332 static ushort QT_FASTCALL toCaseFolded(ushort ucs2);
333
334 static UnicodeVersion QT_FASTCALL unicodeVersion(uint ucs4);
335 static UnicodeVersion QT_FASTCALL unicodeVersion(ushort ucs2);
336
337 static UnicodeVersion QT_FASTCALL currentUnicodeVersion();
338
339 static QString QT_FASTCALL decomposition(uint ucs4);
340
341#ifdef QT3_SUPPORT
342 inline QT3_SUPPORT bool mirrored() const { return hasMirrored(); }
343 inline QT3_SUPPORT QChar lower() const { return toLower(); }
344 inline QT3_SUPPORT QChar upper() const { return toUpper(); }
345 static inline QT3_SUPPORT bool networkOrdered() {
346 return QSysInfo::ByteOrder == QSysInfo::BigEndian;
347 }
348#ifdef Q_COMPILER_MANGLES_RETURN_TYPE
349 inline QT3_SUPPORT const char latin1() const { return toLatin1(); }
350 inline QT3_SUPPORT const char ascii() const { return toAscii(); }
351#else
352 inline QT3_SUPPORT char latin1() const { return toLatin1(); }
353 inline QT3_SUPPORT char ascii() const { return toAscii(); }
354#endif
355#endif
356
357private:
358#ifdef QT_NO_CAST_FROM_ASCII
359 QChar(char c);
360 QChar(uchar c);
361#endif
362 ushort ucs;
363}
364#if (defined(__arm__) && defined(QT_NO_ARM_EABI))
365 Q_PACKED
366#endif
367;
368
369Q_DECLARE_TYPEINFO(QChar, Q_MOVABLE_TYPE);
370
371inline QChar::QChar() : ucs(0) {}
372
373#ifdef Q_COMPILER_MANGLES_RETURN_TYPE
374inline const char QChar::toLatin1() const { return ucs > 0xff ? '\0' : char(ucs); }
375#else
376inline char QChar::toLatin1() const { return ucs > 0xff ? '\0' : char(ucs); }
377#endif
378inline QChar QChar::fromLatin1(char c) { return QChar(ushort(uchar(c))); }
379
380inline QChar::QChar(uchar c, uchar r) : ucs(ushort((r << 8) | c)){}
381inline QChar::QChar(short rc) : ucs(ushort(rc)){}
382inline QChar::QChar(uint rc) : ucs(ushort(rc & 0xffff)){}
383inline QChar::QChar(int rc) : ucs(ushort(rc & 0xffff)){}
384inline QChar::QChar(SpecialCharacter s) : ucs(ushort(s)) {}
385inline QChar::QChar(QLatin1Char ch) : ucs(ch.unicode()) {}
386
387inline void QChar::setCell(uchar acell)
388{ ucs = ushort((ucs & 0xff00) + acell); }
389inline void QChar::setRow(uchar arow)
390{ ucs = ushort((ushort(arow)<<8) + (ucs&0xff)); }
391
392inline bool operator==(QChar c1, QChar c2) { return c1.unicode() == c2.unicode(); }
393inline bool operator!=(QChar c1, QChar c2) { return c1.unicode() != c2.unicode(); }
394inline bool operator<=(QChar c1, QChar c2) { return c1.unicode() <= c2.unicode(); }
395inline bool operator>=(QChar c1, QChar c2) { return c1.unicode() >= c2.unicode(); }
396inline bool operator<(QChar c1, QChar c2) { return c1.unicode() < c2.unicode(); }
397inline bool operator>(QChar c1, QChar c2) { return c1.unicode() > c2.unicode(); }
398
399#ifndef QT_NO_DATASTREAM
400Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QChar &);
401Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QChar &);
402#endif
403
404QT_END_NAMESPACE
405
406QT_END_HEADER
407
408#endif // QCHAR_H
409