Qt 4.8
qchar.h
Go to the documentation of this file.
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 
48 
50 
51 QT_MODULE(Core)
52 
53 class QString;
54 
56 {
57 public:
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 
67 private:
68  char ch;
69 };
70 
71 
73 public:
74  QChar();
75 #ifndef QT_NO_CAST_FROM_ASCII
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);
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 
113 
117 
121 
127 
133 
141 
142  Symbol_Math, // Sm
146 
147  Punctuation_Dask = Punctuation_Dash // ### Qt 5: remove
148  };
149 
151  {
152  DirL, DirR, DirEN, DirES, DirET, DirAN, DirCS, DirB, DirS, DirWS, DirON,
153  DirLRE, DirLRO, DirAL, DirRLE, DirRLO, DirPDF, DirNSM, DirBN
154  };
155 
157  {
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 
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 
213  Unicode_Unassigned, // ### Qt 5: assign with some constantly big value
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 
357 private:
358 #ifdef QT_NO_CAST_FROM_ASCII
359  QChar(char c);
360  QChar(uchar c);
361 #endif
363 }
364 #if (defined(__arm__) && defined(QT_NO_ARM_EABI))
365  Q_PACKED
366 #endif
367 ;
368 
370 
371 inline QChar::QChar() : ucs(0) {}
372 
373 #ifdef Q_COMPILER_MANGLES_RETURN_TYPE
374 inline const char QChar::toLatin1() const { return ucs > 0xff ? '\0' : char(ucs); }
375 #else
376 inline char QChar::toLatin1() const { return ucs > 0xff ? '\0' : char(ucs); }
377 #endif
378 inline QChar QChar::fromLatin1(char c) { return QChar(ushort(uchar(c))); }
379 
380 inline QChar::QChar(uchar c, uchar r) : ucs(ushort((r << 8) | c)){}
381 inline QChar::QChar(short rc) : ucs(ushort(rc)){}
382 inline QChar::QChar(uint rc) : ucs(ushort(rc & 0xffff)){}
383 inline QChar::QChar(int rc) : ucs(ushort(rc & 0xffff)){}
385 inline QChar::QChar(QLatin1Char ch) : ucs(ch.unicode()) {}
386 
387 inline void QChar::setCell(uchar acell)
388 { ucs = ushort((ucs & 0xff00) + acell); }
389 inline void QChar::setRow(uchar arow)
390 { ucs = ushort((ushort(arow)<<8) + (ucs&0xff)); }
391 
392 inline bool operator==(QChar c1, QChar c2) { return c1.unicode() == c2.unicode(); }
393 inline bool operator!=(QChar c1, QChar c2) { return c1.unicode() != c2.unicode(); }
394 inline bool operator<=(QChar c1, QChar c2) { return c1.unicode() <= c2.unicode(); }
395 inline bool operator>=(QChar c1, QChar c2) { return c1.unicode() >= c2.unicode(); }
396 inline bool operator<(QChar c1, QChar c2) { return c1.unicode() < c2.unicode(); }
397 inline bool operator>(QChar c1, QChar c2) { return c1.unicode() > c2.unicode(); }
398 
399 #ifndef QT_NO_DATASTREAM
402 #endif
403 
405 
407 
408 #endif // QCHAR_H
int operator>(QChar c1, QChar c2)
Returns true if the numeric Unicode value of c1 is greater than that of c2; otherwise returns false...
Definition: qchar.h:397
#define Q_PACKED
Definition: qglobal.h:815
Joining
This enum type defines the Unicode joining attributes.
Definition: qchar.h:182
Category
This enum maps the Unicode character categories.
Definition: qchar.h:106
unsigned char c[8]
Definition: qnumeric_p.h:62
QChar()
Constructs a null QChar (&#39;\0&#39;).
Definition: qchar.h:371
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
QChar(ushort rc)
Constructs a QChar for the character with Unicode code point code.
Definition: qchar.h:81
int operator<=(QChar c1, QChar c2)
Returns true if the numeric Unicode value of c1 is less than or equal to that of c2; otherwise return...
Definition: qchar.h:394
#define QT_MODULE(x)
Definition: qglobal.h:2783
char toLatin1() const
Converts a Latin-1 character to an 8-bit ASCII representation of the character.
Definition: qchar.h:63
ushort ucs
Definition: qchar.h:362
ushort unicode() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qchar.h:251
#define QT_BEGIN_HEADER
Definition: qglobal.h:136
bool isNull() const
Returns true if the character is the Unicode character 0x0000 (&#39;\0&#39;); otherwise returns false...
Definition: qchar.h:262
int operator!=(QChar c1, QChar c2)
Returns true if c1 and c2 are not the same Unicode character; otherwise returns false.
Definition: qchar.h:393
static bool isHighSurrogate(uint ucs4)
Returns true if the UCS-4-encoded character specified by ucs4 is the high part of a utf16 surrogate (...
Definition: qchar.h:288
bool operator==(QChar c1, QChar c2)
Returns true if c1 and c2 are the same Unicode character; otherwise returns false.
Definition: qchar.h:392
char ch
Definition: qchar.h:68
bool isLowSurrogate() const
Returns true if the QChar is the low part of a utf16 surrogate (ie.
Definition: qchar.h:279
int operator<(QChar c1, QChar c2)
Returns true if the numeric Unicode value of c1 is less than that of c2; otherwise returns false...
Definition: qchar.h:396
static bool isNumber(char s)
static bool isLowSurrogate(uint ucs4)
Returns true if the UCS-4-encoded character specified by ucs4 is the low part of a utf16 surrogate (i...
Definition: qchar.h:291
The QString class provides a Unicode character string.
Definition: qstring.h:83
bool isHighSurrogate() const
Returns true if the QChar is the high part of a utf16 surrogate (ie.
Definition: qchar.h:276
#define QT_FASTCALL
Definition: qglobal.h:1161
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
bool isLower() const
Returns true if the character is a lowercase letter, i.
Definition: qchar.h:272
static ushort highSurrogate(uint ucs4)
Returns the high surrogate value of a ucs4 code point.
Definition: qchar.h:303
static ushort lowSurrogate(uint ucs4)
Returns the low surrogate value of a ucs4 code point.
Definition: qchar.h:306
unsigned char uchar
Definition: qglobal.h:994
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
static bool requiresSurrogates(uint ucs4)
Returns true if the UCS-4-encoded character specified by ucs4 can be split into the high and low part...
Definition: qchar.h:294
Q_DECLARE_TYPEINFO(QChar, Q_MOVABLE_TYPE)
unsigned int uint
Definition: qglobal.h:996
static QChar fromLatin1(char c)
Converts the Latin-1 character c to its equivalent QChar.
Definition: qchar.h:378
#define QT_ASCII_CAST_WARN_CONSTRUCTOR
Definition: qglobal.h:1145
static bool isDigit(ushort ch)
QDataStream & operator>>(QDataStream &in, QChar &chr)
Reads a char from the stream in into char chr.
Definition: qchar.cpp:1558
SpecialCharacter
Definition: qchar.h:85
UnicodeVersion
Specifies which version of the [Unicode standard](http://www.
Definition: qchar.h:212
CombiningClass
This enum type defines names for some of the Unicode combining classes.
Definition: qchar.h:187
bool isUpper() const
Returns true if the character is an uppercase letter, i.
Definition: qchar.h:273
ushort unicode() const
Converts a Latin-1 character to an 16-bit-encoded Unicode representation of the character.
Definition: qchar.h:64
Direction
This enum type defines the Unicode direction attributes.
Definition: qchar.h:150
#define Q_CORE_EXPORT
Definition: qglobal.h:1449
unsigned short ushort
Definition: qglobal.h:995
int operator>=(QChar c1, QChar c2)
Returns true if the numeric Unicode value of c1 is greater than or equal to that of c2; otherwise ret...
Definition: qchar.h:395
QLatin1Char(char c)
Constructs a Latin-1 character for c.
Definition: qchar.h:58
uchar cell() const
Returns the cell (least significant byte) of the Unicode character.
Definition: qchar.h:283
static uint surrogateToUcs4(QChar high, QChar low)
Converts a utf16 surrogate pair (high, low) to its ucs4 code point.
Definition: qchar.h:300
static uint surrogateToUcs4(ushort high, ushort low)
Converts a UTF16 surrogate pair with the given high and low values to its UCS-4 code point...
Definition: qchar.h:297
char toLatin1() const
Returns the Latin-1 character equivalent to the QChar, or 0.
Definition: qchar.h:376
void setRow(uchar row)
Definition: qchar.h:389
The QDataStream class provides serialization of binary data to a QIODevice.
Definition: qdatastream.h:71
ushort & unicode()
Returns a reference to the numeric Unicode value of the QChar.
Definition: qchar.h:256
bool isTitleCase() const
Returns true if the character is a titlecase letter, i.
Definition: qchar.h:274
#define QT_END_HEADER
Definition: qglobal.h:137
QDataStream & operator<<(QDataStream &out, const QChar &chr)
Writes the char chr to the stream out.
Definition: qchar.cpp:1542
uchar row() const
Returns the row (most significant byte) of the Unicode character.
Definition: qchar.h:284
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
void setCell(uchar cell)
Definition: qchar.h:387
Qt::LayoutDirection direction
Decomposition
This enum type defines the Unicode decomposition attributes.
Definition: qchar.h:156