00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 #ifndef QCHAR_H
00043 #define QCHAR_H
00044
00045 #include <QtCore/qglobal.h>
00046
00047 QT_BEGIN_HEADER
00048
00049 QT_BEGIN_NAMESPACE
00050
00051 QT_MODULE(Core)
00052
00053 class QString;
00054
00055 struct QLatin1Char
00056 {
00057 public:
00058 inline explicit QLatin1Char(char c) : ch(c) {}
00059 #ifdef Q_COMPILER_MANGLES_RETURN_TYPE
00060 inline const char toLatin1() const { return ch; }
00061 inline const ushort unicode() const { return ushort(uchar(ch)); }
00062 #else
00063 inline char toLatin1() const { return ch; }
00064 inline ushort unicode() const { return ushort(uchar(ch)); }
00065 #endif
00066
00067 private:
00068 char ch;
00069 };
00070
00071
00072 class Q_CORE_EXPORT QChar {
00073 public:
00074 QChar();
00075 #ifndef QT_NO_CAST_FROM_ASCII
00076 QT_ASCII_CAST_WARN_CONSTRUCTOR QChar(char c);
00077 QT_ASCII_CAST_WARN_CONSTRUCTOR QChar(uchar c);
00078 #endif
00079 QChar(QLatin1Char ch);
00080 QChar(uchar c, uchar r);
00081 inline QChar(ushort rc) : ucs(rc){}
00082 QChar(short rc);
00083 QChar(uint rc);
00084 QChar(int rc);
00085 enum SpecialCharacter {
00086 Null = 0x0000,
00087 Nbsp = 0x00a0,
00088 ReplacementCharacter = 0xfffd,
00089 ObjectReplacementCharacter = 0xfffc,
00090 ByteOrderMark = 0xfeff,
00091 ByteOrderSwapped = 0xfffe,
00092 #ifdef QT3_SUPPORT
00093 null = Null,
00094 replacement = ReplacementCharacter,
00095 byteOrderMark = ByteOrderMark,
00096 byteOrderSwapped = ByteOrderSwapped,
00097 nbsp = Nbsp,
00098 #endif
00099 ParagraphSeparator = 0x2029,
00100 LineSeparator = 0x2028
00101 };
00102 QChar(SpecialCharacter sc);
00103
00104
00105
00106 enum Category
00107 {
00108 NoCategory,
00109
00110 Mark_NonSpacing,
00111 Mark_SpacingCombining,
00112 Mark_Enclosing,
00113
00114 Number_DecimalDigit,
00115 Number_Letter,
00116 Number_Other,
00117
00118 Separator_Space,
00119 Separator_Line,
00120 Separator_Paragraph,
00121
00122 Other_Control,
00123 Other_Format,
00124 Other_Surrogate,
00125 Other_PrivateUse,
00126 Other_NotAssigned,
00127
00128 Letter_Uppercase,
00129 Letter_Lowercase,
00130 Letter_Titlecase,
00131 Letter_Modifier,
00132 Letter_Other,
00133
00134 Punctuation_Connector,
00135 Punctuation_Dash,
00136 Punctuation_Open,
00137 Punctuation_Close,
00138 Punctuation_InitialQuote,
00139 Punctuation_FinalQuote,
00140 Punctuation_Other,
00141
00142 Symbol_Math,
00143 Symbol_Currency,
00144 Symbol_Modifier,
00145 Symbol_Other,
00146
00147 Punctuation_Dask = Punctuation_Dash
00148 };
00149
00150 enum Direction
00151 {
00152 DirL, DirR, DirEN, DirES, DirET, DirAN, DirCS, DirB, DirS, DirWS, DirON,
00153 DirLRE, DirLRO, DirAL, DirRLE, DirRLO, DirPDF, DirNSM, DirBN
00154 };
00155
00156 enum Decomposition
00157 {
00158 NoDecomposition,
00159 Canonical,
00160 Font,
00161 NoBreak,
00162 Initial,
00163 Medial,
00164 Final,
00165 Isolated,
00166 Circle,
00167 Super,
00168 Sub,
00169 Vertical,
00170 Wide,
00171 Narrow,
00172 Small,
00173 Square,
00174 Compat,
00175 Fraction
00176
00177 #ifdef QT3_SUPPORT
00178 , Single = NoDecomposition
00179 #endif
00180 };
00181
00182 enum Joining
00183 {
00184 OtherJoining, Dual, Right, Center
00185 };
00186
00187 enum CombiningClass
00188 {
00189 Combining_BelowLeftAttached = 200,
00190 Combining_BelowAttached = 202,
00191 Combining_BelowRightAttached = 204,
00192 Combining_LeftAttached = 208,
00193 Combining_RightAttached = 210,
00194 Combining_AboveLeftAttached = 212,
00195 Combining_AboveAttached = 214,
00196 Combining_AboveRightAttached = 216,
00197
00198 Combining_BelowLeft = 218,
00199 Combining_Below = 220,
00200 Combining_BelowRight = 222,
00201 Combining_Left = 224,
00202 Combining_Right = 226,
00203 Combining_AboveLeft = 228,
00204 Combining_Above = 230,
00205 Combining_AboveRight = 232,
00206
00207 Combining_DoubleBelow = 233,
00208 Combining_DoubleAbove = 234,
00209 Combining_IotaSubscript = 240
00210 };
00211
00212 enum UnicodeVersion {
00213 Unicode_Unassigned,
00214 Unicode_1_1,
00215 Unicode_2_0,
00216 Unicode_2_1_2,
00217 Unicode_3_0,
00218 Unicode_3_1,
00219 Unicode_3_2,
00220 Unicode_4_0,
00221 Unicode_4_1,
00222 Unicode_5_0
00223 };
00224
00225
00226 Category category() const;
00227 Direction direction() const;
00228 Joining joining() const;
00229 bool hasMirrored() const;
00230 unsigned char combiningClass() const;
00231
00232 QChar mirroredChar() const;
00233 QString decomposition() const;
00234 Decomposition decompositionTag() const;
00235
00236 int digitValue() const;
00237 QChar toLower() const;
00238 QChar toUpper() const;
00239 QChar toTitleCase() const;
00240 QChar toCaseFolded() const;
00241
00242 UnicodeVersion unicodeVersion() const;
00243
00244 #ifdef Q_COMPILER_MANGLES_RETURN_TYPE
00245 const char toAscii() const;
00246 inline const char toLatin1() const;
00247 inline const ushort unicode() const { return ucs; }
00248 #else
00249 char toAscii() const;
00250 inline char toLatin1() const;
00251 inline ushort unicode() const { return ucs; }
00252 #endif
00253 #ifdef Q_NO_PACKED_REFERENCE
00254 inline ushort &unicode() { return const_cast<ushort&>(ucs); }
00255 #else
00256 inline ushort &unicode() { return ucs; }
00257 #endif
00258
00259 static QChar fromAscii(char c);
00260 static QChar fromLatin1(char c);
00261
00262 inline bool isNull() const { return ucs == 0; }
00263 bool isPrint() const;
00264 bool isPunct() const;
00265 bool isSpace() const;
00266 bool isMark() const;
00267 bool isLetter() const;
00268 bool isNumber() const;
00269 bool isLetterOrNumber() const;
00270 bool isDigit() const;
00271 bool isSymbol() const;
00272 inline bool isLower() const { return category() == Letter_Lowercase; }
00273 inline bool isUpper() const { return category() == Letter_Uppercase; }
00274 inline bool isTitleCase() const { return category() == Letter_Titlecase; }
00275
00276 inline bool isHighSurrogate() const {
00277 return ((ucs & 0xfc00) == 0xd800);
00278 }
00279 inline bool isLowSurrogate() const {
00280 return ((ucs & 0xfc00) == 0xdc00);
00281 }
00282
00283 inline uchar cell() const { return uchar(ucs & 0xff); }
00284 inline uchar row() const { return uchar((ucs>>8)&0xff); }
00285 inline void setCell(uchar cell);
00286 inline void setRow(uchar row);
00287
00288 static inline bool isHighSurrogate(uint ucs4) {
00289 return ((ucs4 & 0xfffffc00) == 0xd800);
00290 }
00291 static inline bool isLowSurrogate(uint ucs4) {
00292 return ((ucs4 & 0xfffffc00) == 0xdc00);
00293 }
00294 static inline bool requiresSurrogates(uint ucs4) {
00295 return (ucs4 >= 0x10000);
00296 }
00297 static inline uint surrogateToUcs4(ushort high, ushort low) {
00298 return (uint(high)<<10) + low - 0x35fdc00;
00299 }
00300 static inline uint surrogateToUcs4(QChar high, QChar low) {
00301 return (uint(high.ucs)<<10) + low.ucs - 0x35fdc00;
00302 }
00303 static inline ushort highSurrogate(uint ucs4) {
00304 return ushort((ucs4>>10) + 0xd7c0);
00305 }
00306 static inline ushort lowSurrogate(uint ucs4) {
00307 return ushort(ucs4%0x400 + 0xdc00);
00308 }
00309
00310 static Category QT_FASTCALL category(uint ucs4);
00311 static Category QT_FASTCALL category(ushort ucs2);
00312 static Direction QT_FASTCALL direction(uint ucs4);
00313 static Direction QT_FASTCALL direction(ushort ucs2);
00314 static Joining QT_FASTCALL joining(uint ucs4);
00315 static Joining QT_FASTCALL joining(ushort ucs2);
00316 static unsigned char QT_FASTCALL combiningClass(uint ucs4);
00317 static unsigned char QT_FASTCALL combiningClass(ushort ucs2);
00318
00319 static uint QT_FASTCALL mirroredChar(uint ucs4);
00320 static ushort QT_FASTCALL mirroredChar(ushort ucs2);
00321 static Decomposition QT_FASTCALL decompositionTag(uint ucs4);
00322
00323 static int QT_FASTCALL digitValue(uint ucs4);
00324 static int QT_FASTCALL digitValue(ushort ucs2);
00325 static uint QT_FASTCALL toLower(uint ucs4);
00326 static ushort QT_FASTCALL toLower(ushort ucs2);
00327 static uint QT_FASTCALL toUpper(uint ucs4);
00328 static ushort QT_FASTCALL toUpper(ushort ucs2);
00329 static uint QT_FASTCALL toTitleCase(uint ucs4);
00330 static ushort QT_FASTCALL toTitleCase(ushort ucs2);
00331 static uint QT_FASTCALL toCaseFolded(uint ucs4);
00332 static ushort QT_FASTCALL toCaseFolded(ushort ucs2);
00333
00334 static UnicodeVersion QT_FASTCALL unicodeVersion(uint ucs4);
00335 static UnicodeVersion QT_FASTCALL unicodeVersion(ushort ucs2);
00336
00337 static QString QT_FASTCALL decomposition(uint ucs4);
00338
00339 #ifdef QT3_SUPPORT
00340 inline QT3_SUPPORT bool mirrored() const { return hasMirrored(); }
00341 inline QT3_SUPPORT QChar lower() const { return toLower(); }
00342 inline QT3_SUPPORT QChar upper() const { return toUpper(); }
00343 static inline QT3_SUPPORT bool networkOrdered() {
00344 return QSysInfo::ByteOrder == QSysInfo::BigEndian;
00345 }
00346 #ifdef Q_COMPILER_MANGLES_RETURN_TYPE
00347 inline QT3_SUPPORT const char latin1() const { return toLatin1(); }
00348 inline QT3_SUPPORT const char ascii() const { return toAscii(); }
00349 #else
00350 inline QT3_SUPPORT char latin1() const { return toLatin1(); }
00351 inline QT3_SUPPORT char ascii() const { return toAscii(); }
00352 #endif
00353 #endif
00354
00355 private:
00356 #ifdef QT_NO_CAST_FROM_ASCII
00357 QChar(char c);
00358 QChar(uchar c);
00359 #endif
00360 ushort ucs;
00361 };
00362
00363 Q_DECLARE_TYPEINFO(QChar, Q_MOVABLE_TYPE);
00364
00365 inline QChar::QChar() : ucs(0) {}
00366
00367 #ifdef Q_COMPILER_MANGLES_RETURN_TYPE
00368 inline const char QChar::toLatin1() const { return ucs > 0xff ? '\0' : char(ucs); }
00369 #else
00370 inline char QChar::toLatin1() const { return ucs > 0xff ? '\0' : char(ucs); }
00371 #endif
00372 inline QChar QChar::fromLatin1(char c) { return QChar(ushort(uchar(c))); }
00373
00374 inline QChar::QChar(uchar c, uchar r) : ucs(ushort((r << 8) | c)){}
00375 inline QChar::QChar(short rc) : ucs(ushort(rc)){}
00376 inline QChar::QChar(uint rc) : ucs(ushort(rc & 0xffff)){}
00377 inline QChar::QChar(int rc) : ucs(ushort(rc & 0xffff)){}
00378 inline QChar::QChar(SpecialCharacter s) : ucs(ushort(s)) {}
00379 inline QChar::QChar(QLatin1Char ch) : ucs(ch.unicode()) {}
00380
00381 inline void QChar::setCell(uchar acell)
00382 { ucs = ushort((ucs & 0xff00) + acell); }
00383 inline void QChar::setRow(uchar arow)
00384 { ucs = ushort((ushort(arow)<<8) + (ucs&0xff)); }
00385
00386 inline bool operator==(QChar c1, QChar c2) { return c1.unicode() == c2.unicode(); }
00387 inline bool operator!=(QChar c1, QChar c2) { return c1.unicode() != c2.unicode(); }
00388 inline bool operator<=(QChar c1, QChar c2) { return c1.unicode() <= c2.unicode(); }
00389 inline bool operator>=(QChar c1, QChar c2) { return c1.unicode() >= c2.unicode(); }
00390 inline bool operator<(QChar c1, QChar c2) { return c1.unicode() < c2.unicode(); }
00391 inline bool operator>(QChar c1, QChar c2) { return c1.unicode() > c2.unicode(); }
00392
00393 #ifndef QT_NO_DATASTREAM
00394 Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QChar &);
00395 Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QChar &);
00396 #endif
00397
00398 QT_END_NAMESPACE
00399
00400 QT_END_HEADER
00401
00402 #endif // QCHAR_H