Eneboo - Documentación para desarrolladores
|
00001 /**************************************************************************** 00002 ** $Id: qt/qstring.h 3.3.8 edited Jan 11 14:38 $ 00003 ** 00004 ** Definition of the QString class, and related Unicode functions. 00005 ** 00006 ** Created : 920609 00007 ** 00008 ** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved. 00009 ** 00010 ** This file is part of the tools module of the Qt GUI Toolkit. 00011 ** 00012 ** This file may be distributed under the terms of the Q Public License 00013 ** as defined by Trolltech ASA of Norway and appearing in the file 00014 ** LICENSE.QPL included in the packaging of this file. 00015 ** 00016 ** This file may be distributed and/or modified under the terms of the 00017 ** GNU General Public License version 2 as published by the Free Software 00018 ** Foundation and appearing in the file LICENSE.GPL included in the 00019 ** packaging of this file. 00020 ** 00021 ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition 00022 ** licenses may use this file in accordance with the Qt Commercial License 00023 ** Agreement provided with the Software. 00024 ** 00025 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 00026 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 00027 ** 00028 ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for 00029 ** information about Qt Commercial License Agreements. 00030 ** See http://www.trolltech.com/qpl/ for QPL licensing information. 00031 ** See http://www.trolltech.com/gpl/ for GPL licensing information. 00032 ** 00033 ** Contact info@trolltech.com if any conditions of this licensing are 00034 ** not clear to you. 00035 ** 00036 **********************************************************************/ 00037 00038 #ifndef QSTRING_H 00039 #define QSTRING_H 00040 00041 #ifndef QT_H 00042 #include "qcstring.h" 00043 #endif // QT_H 00044 00045 #ifndef QT_NO_CAST_ASCII 00046 #include <limits.h> 00047 #endif 00048 00049 #ifndef QT_NO_STL 00050 #if defined ( Q_CC_MSVC_NET ) && _MSC_VER < 1310 // Avoids nasty warning for xlocale, line 450 00051 # pragma warning ( push ) 00052 # pragma warning ( disable : 4189 ) 00053 # include <string> 00054 # pragma warning ( pop ) 00055 #else 00056 # include <string> 00057 #endif 00058 #if defined(Q_WRONG_SB_CTYPE_MACROS) && defined(_SB_CTYPE_MACROS) 00059 #undef _SB_CTYPE_MACROS 00060 #endif 00061 #endif 00062 00063 00064 /***************************************************************************** 00065 QString class 00066 *****************************************************************************/ 00067 00068 class QRegExp; 00069 class QString; 00070 class QCharRef; 00071 template <class T> class QDeepCopy; 00072 00073 class Q_EXPORT QChar { 00074 public: 00075 QChar(); 00076 QChar( char c ); 00077 QChar( uchar c ); 00078 QChar( uchar c, uchar r ); 00079 QChar( const QChar& c ); // ### remove in 4.0 to allow compiler optimization 00080 QChar( ushort rc ); 00081 QChar( short rc ); 00082 QChar( uint rc ); 00083 QChar( int rc ); 00084 00085 QT_STATIC_CONST QChar null; // 0000 00086 QT_STATIC_CONST QChar replacement; // FFFD 00087 QT_STATIC_CONST QChar byteOrderMark; // FEFF 00088 QT_STATIC_CONST QChar byteOrderSwapped; // FFFE 00089 QT_STATIC_CONST QChar nbsp; // 00A0 00090 00091 // Unicode information 00092 00093 enum Category 00094 { 00095 NoCategory, 00096 00097 Mark_NonSpacing, // Mn 00098 Mark_SpacingCombining, // Mc 00099 Mark_Enclosing, // Me 00100 00101 Number_DecimalDigit, // Nd 00102 Number_Letter, // Nl 00103 Number_Other, // No 00104 00105 Separator_Space, // Zs 00106 Separator_Line, // Zl 00107 Separator_Paragraph, // Zp 00108 00109 Other_Control, // Cc 00110 Other_Format, // Cf 00111 Other_Surrogate, // Cs 00112 Other_PrivateUse, // Co 00113 Other_NotAssigned, // Cn 00114 00115 Letter_Uppercase, // Lu 00116 Letter_Lowercase, // Ll 00117 Letter_Titlecase, // Lt 00118 Letter_Modifier, // Lm 00119 Letter_Other, // Lo 00120 00121 Punctuation_Connector, // Pc 00122 Punctuation_Dash, // Pd 00123 Punctuation_Dask = Punctuation_Dash, // oops 00124 Punctuation_Open, // Ps 00125 Punctuation_Close, // Pe 00126 Punctuation_InitialQuote, // Pi 00127 Punctuation_FinalQuote, // Pf 00128 Punctuation_Other, // Po 00129 00130 Symbol_Math, // Sm 00131 Symbol_Currency, // Sc 00132 Symbol_Modifier, // Sk 00133 Symbol_Other // So 00134 }; 00135 00136 enum Direction 00137 { 00138 DirL, DirR, DirEN, DirES, DirET, DirAN, DirCS, DirB, DirS, DirWS, DirON, 00139 DirLRE, DirLRO, DirAL, DirRLE, DirRLO, DirPDF, DirNSM, DirBN 00140 }; 00141 00142 enum Decomposition 00143 { 00144 Single, Canonical, Font, NoBreak, Initial, Medial, 00145 Final, Isolated, Circle, Super, Sub, Vertical, 00146 Wide, Narrow, Small, Square, Compat, Fraction 00147 }; 00148 00149 enum Joining 00150 { 00151 OtherJoining, Dual, Right, Center 00152 }; 00153 00154 enum CombiningClass 00155 { 00156 Combining_BelowLeftAttached = 200, 00157 Combining_BelowAttached = 202, 00158 Combining_BelowRightAttached = 204, 00159 Combining_LeftAttached = 208, 00160 Combining_RightAttached = 210, 00161 Combining_AboveLeftAttached = 212, 00162 Combining_AboveAttached = 214, 00163 Combining_AboveRightAttached = 216, 00164 00165 Combining_BelowLeft = 218, 00166 Combining_Below = 220, 00167 Combining_BelowRight = 222, 00168 Combining_Left = 224, 00169 Combining_Right = 226, 00170 Combining_AboveLeft = 228, 00171 Combining_Above = 230, 00172 Combining_AboveRight = 232, 00173 00174 Combining_DoubleBelow = 233, 00175 Combining_DoubleAbove = 234, 00176 Combining_IotaSubscript = 240 00177 }; 00178 00179 // ****** WHEN ADDING FUNCTIONS, CONSIDER ADDING TO QCharRef TOO 00180 00181 int digitValue() const; 00182 QChar lower() const; 00183 QChar upper() const; 00184 00185 Category category() const; 00186 Direction direction() const; 00187 Joining joining() const; 00188 bool mirrored() const; 00189 QChar mirroredChar() const; 00190 const QString &decomposition() const; // ### return just QString in 4.0 00191 Decomposition decompositionTag() const; 00192 unsigned char combiningClass() const; 00193 00194 char latin1() const { return ucs > 0xff ? 0 : (char) ucs; } 00195 ushort unicode() const { return ucs; } 00196 #ifdef Q_NO_PACKED_REFERENCE 00197 ushort &unicode() { return *(&ucs); } 00198 #else 00199 ushort &unicode() { return ucs; } 00200 #endif 00201 #ifndef QT_NO_CAST_ASCII 00202 // like all ifdef'd code this is undocumented 00203 operator char() const { return latin1(); } 00204 #endif 00205 00206 bool isNull() const { return unicode()==0; } 00207 bool isPrint() const; 00208 bool isPunct() const; 00209 bool isSpace() const; 00210 bool isMark() const; 00211 bool isLetter() const; 00212 bool isNumber() const; 00213 bool isLetterOrNumber() const; 00214 bool isDigit() const; 00215 bool isSymbol() const; 00216 00217 uchar cell() const { return ((uchar) ucs & 0xff); } 00218 uchar row() const { return ((uchar) (ucs>>8)&0xff); } 00219 void setCell( uchar cell ) { ucs = (ucs & 0xff00) + cell; } 00220 void setRow( uchar row ) { ucs = (((ushort) row)<<8) + (ucs&0xff); } 00221 00222 static bool networkOrdered() { 00223 int wordSize; 00224 bool bigEndian = FALSE; 00225 qSysInfo( &wordSize, &bigEndian ); 00226 return bigEndian; 00227 } 00228 00229 friend inline bool operator==( char ch, QChar c ); 00230 friend inline bool operator==( QChar c, char ch ); 00231 friend inline bool operator==( QChar c1, QChar c2 ); 00232 friend inline bool operator!=( QChar c1, QChar c2 ); 00233 friend inline bool operator!=( char ch, QChar c ); 00234 friend inline bool operator!=( QChar c, char ch ); 00235 friend inline bool operator<=( QChar c, char ch ); 00236 friend inline bool operator<=( char ch, QChar c ); 00237 friend inline bool operator<=( QChar c1, QChar c2 ); 00238 00239 private: 00240 ushort ucs; 00241 #if defined(QT_QSTRING_UCS_4) 00242 ushort grp; 00243 #endif 00244 } Q_PACKED; 00245 00246 inline QChar::QChar() : ucs( 0 ) 00247 #ifdef QT_QSTRING_UCS_4 00248 , grp( 0 ) 00249 #endif 00250 { 00251 } 00252 inline QChar::QChar( char c ) : ucs( (uchar)c ) 00253 #ifdef QT_QSTRING_UCS_4 00254 , grp( 0 ) 00255 #endif 00256 { 00257 } 00258 inline QChar::QChar( uchar c ) : ucs( c ) 00259 #ifdef QT_QSTRING_UCS_4 00260 , grp( 0 ) 00261 #endif 00262 { 00263 } 00264 inline QChar::QChar( uchar c, uchar r ) : ucs( (r << 8) | c ) 00265 #ifdef QT_QSTRING_UCS_4 00266 , grp( 0 ) 00267 #endif 00268 { 00269 } 00270 inline QChar::QChar( const QChar& c ) : ucs( c.ucs ) 00271 #ifdef QT_QSTRING_UCS_4 00272 , grp( c.grp ) 00273 #endif 00274 { 00275 } 00276 00277 inline QChar::QChar( ushort rc ) : ucs( rc ) 00278 #ifdef QT_QSTRING_UCS_4 00279 , grp( 0 ) 00280 #endif 00281 { 00282 } 00283 inline QChar::QChar( short rc ) : ucs( (ushort) rc ) 00284 #ifdef QT_QSTRING_UCS_4 00285 , grp( 0 ) 00286 #endif 00287 { 00288 } 00289 inline QChar::QChar( uint rc ) : ucs( (ushort ) (rc & 0xffff) ) 00290 #ifdef QT_QSTRING_UCS_4 00291 , grp( (ushort) ((rc >> 16) & 0xffff) ) 00292 #endif 00293 { 00294 } 00295 inline QChar::QChar( int rc ) : ucs( (ushort) (rc & 0xffff) ) 00296 #ifdef QT_QSTRING_UCS_4 00297 , grp( (ushort) ((rc >> 16) & 0xffff) ) 00298 #endif 00299 { 00300 } 00301 00302 inline bool operator==( char ch, QChar c ) 00303 { 00304 return ((uchar) ch) == c.ucs; 00305 } 00306 00307 inline bool operator==( QChar c, char ch ) 00308 { 00309 return ((uchar) ch) == c.ucs; 00310 } 00311 00312 inline bool operator==( QChar c1, QChar c2 ) 00313 { 00314 return c1.ucs == c2.ucs; 00315 } 00316 00317 inline bool operator!=( QChar c1, QChar c2 ) 00318 { 00319 return c1.ucs != c2.ucs; 00320 } 00321 00322 inline bool operator!=( char ch, QChar c ) 00323 { 00324 return ((uchar)ch) != c.ucs; 00325 } 00326 00327 inline bool operator!=( QChar c, char ch ) 00328 { 00329 return ((uchar) ch) != c.ucs; 00330 } 00331 00332 inline bool operator<=( QChar c, char ch ) 00333 { 00334 return c.ucs <= ((uchar) ch); 00335 } 00336 00337 inline bool operator<=( char ch, QChar c ) 00338 { 00339 return ((uchar) ch) <= c.ucs; 00340 } 00341 00342 inline bool operator<=( QChar c1, QChar c2 ) 00343 { 00344 return c1.ucs <= c2.ucs; 00345 } 00346 00347 inline bool operator>=( QChar c, char ch ) { return ch <= c; } 00348 inline bool operator>=( char ch, QChar c ) { return c <= ch; } 00349 inline bool operator>=( QChar c1, QChar c2 ) { return c2 <= c1; } 00350 inline bool operator<( QChar c, char ch ) { return !(ch<=c); } 00351 inline bool operator<( char ch, QChar c ) { return !(c<=ch); } 00352 inline bool operator<( QChar c1, QChar c2 ) { return !(c2<=c1); } 00353 inline bool operator>( QChar c, char ch ) { return !(ch>=c); } 00354 inline bool operator>( char ch, QChar c ) { return !(c>=ch); } 00355 inline bool operator>( QChar c1, QChar c2 ) { return !(c2>=c1); } 00356 00357 // internal 00358 struct Q_EXPORT QStringData : public QShared { 00359 QStringData() : 00360 QShared(), unicode(0), ascii(0), len(0), issimpletext(TRUE), maxl(0), islatin1(FALSE) { ref(); } 00361 QStringData(QChar *u, uint l, uint m) : 00362 QShared(), unicode(u), ascii(0), len(l), issimpletext(FALSE), maxl(m), islatin1(FALSE) { } 00363 ~QStringData() { if ( unicode ) delete[] ((char*)unicode); 00364 if ( ascii ) delete[] ascii; } 00365 00366 void deleteSelf(); 00367 QChar *unicode; 00368 char *ascii; 00369 void setDirty() { 00370 if ( ascii ) { 00371 delete [] ascii; 00372 ascii = 0; 00373 } 00374 issimpletext = FALSE; 00375 } 00376 #ifdef Q_OS_MAC9 00377 uint len; 00378 #else 00379 uint len : 30; 00380 #endif 00381 uint issimpletext : 1; 00382 #ifdef Q_OS_MAC9 00383 uint maxl; 00384 #else 00385 uint maxl : 30; 00386 #endif 00387 uint islatin1 : 1; 00388 00389 private: 00390 #if defined(Q_DISABLE_COPY) 00391 QStringData( const QStringData& ); 00392 QStringData& operator=( const QStringData& ); 00393 #endif 00394 }; 00395 00396 00397 class Q_EXPORT QString 00398 { 00399 public: 00400 QString(); // make null string 00401 QString( QChar ); // one-char string 00402 QString( const QString & ); // impl-shared copy 00403 QString( const QByteArray& ); // deep copy 00404 QString( const QChar* unicode, uint length ); // deep copy 00405 #ifndef QT_NO_CAST_ASCII 00406 QString( const char *str ); // deep copy 00407 #endif 00408 #ifndef QT_NO_STL 00409 QString( const std::string& ); // deep copy 00410 #endif 00411 ~QString(); 00412 00413 QString &operator=( const QString & ); // impl-shared copy 00414 QString &operator=( const char * ); // deep copy 00415 #ifndef QT_NO_STL 00416 QString &operator=( const std::string& ); // deep copy 00417 #endif 00418 QString &operator=( const QCString& ); // deep copy 00419 QString &operator=( QChar c ); 00420 QString &operator=( char c ); 00421 00422 QT_STATIC_CONST QString null; 00423 00424 bool isNull() const; 00425 bool isEmpty() const; 00426 uint length() const; 00427 void truncate( uint pos ); 00428 00429 QString & fill( QChar c, int len = -1 ); 00430 00431 QString copy() const; 00432 00433 QString arg( long a, int fieldWidth = 0, int base = 10 ) const; 00434 QString arg( ulong a, int fieldWidth = 0, int base = 10 ) const; 00435 QString arg( Q_LLONG a, int fieldwidth=0, int base=10 ) const; 00436 QString arg( Q_ULLONG a, int fieldwidth=0, int base=10 ) const; 00437 QString arg( int a, int fieldWidth = 0, int base = 10 ) const; 00438 QString arg( uint a, int fieldWidth = 0, int base = 10 ) const; 00439 QString arg( short a, int fieldWidth = 0, int base = 10 ) const; 00440 QString arg( ushort a, int fieldWidth = 0, int base = 10 ) const; 00441 QString arg( double a, int fieldWidth = 0, char fmt = 'g', 00442 int prec = -1 ) const; 00443 QString arg( char a, int fieldWidth = 0 ) const; 00444 QString arg( QChar a, int fieldWidth = 0 ) const; 00445 QString arg( const QString& a, int fieldWidth = 0 ) const; 00446 QString arg( const QString& a1, const QString& a2 ) const; 00447 QString arg( const QString& a1, const QString& a2, 00448 const QString& a3 ) const; 00449 QString arg( const QString& a1, const QString& a2, const QString& a3, 00450 const QString& a4 ) const; 00451 00452 #ifndef QT_NO_SPRINTF 00453 QString &sprintf( const char* format, ... ) 00454 #if defined(Q_CC_GNU) && !defined(__INSURE__) 00455 __attribute__ ((format (printf, 2, 3))) 00456 #endif 00457 ; 00458 #endif 00459 00460 int find( QChar c, int index=0, bool cs=TRUE ) const; 00461 int find( char c, int index=0, bool cs=TRUE ) const; 00462 int find( const QString &str, int index=0, bool cs=TRUE ) const; 00463 #ifndef QT_NO_REGEXP 00464 int find( const QRegExp &, int index=0 ) const; 00465 #endif 00466 #ifndef QT_NO_CAST_ASCII 00467 int find( const char* str, int index=0 ) const; 00468 #endif 00469 int findRev( QChar c, int index=-1, bool cs=TRUE) const; 00470 int findRev( char c, int index=-1, bool cs=TRUE) const; 00471 int findRev( const QString &str, int index=-1, bool cs=TRUE) const; 00472 #ifndef QT_NO_REGEXP 00473 int findRev( const QRegExp &, int index=-1 ) const; 00474 #endif 00475 #ifndef QT_NO_CAST_ASCII 00476 int findRev( const char* str, int index=-1 ) const; 00477 #endif 00478 int contains( QChar c, bool cs=TRUE ) const; 00479 int contains( char c, bool cs=TRUE ) const 00480 { return contains(QChar(c), cs); } 00481 #ifndef QT_NO_CAST_ASCII 00482 int contains( const char* str, bool cs=TRUE ) const; 00483 #endif 00484 int contains( const QString &str, bool cs=TRUE ) const; 00485 #ifndef QT_NO_REGEXP 00486 int contains( const QRegExp & ) const; 00487 #endif 00488 00489 enum SectionFlags { 00490 SectionDefault = 0x00, 00491 SectionSkipEmpty = 0x01, 00492 SectionIncludeLeadingSep = 0x02, 00493 SectionIncludeTrailingSep = 0x04, 00494 SectionCaseInsensitiveSeps = 0x08 00495 }; 00496 QString section( QChar sep, int start, int end = 0xffffffff, int flags = SectionDefault ) const; 00497 QString section( char sep, int start, int end = 0xffffffff, int flags = SectionDefault ) const; 00498 #ifndef QT_NO_CAST_ASCII 00499 QString section( const char *in_sep, int start, int end = 0xffffffff, int flags = SectionDefault ) const; 00500 #endif 00501 QString section( const QString &in_sep, int start, int end = 0xffffffff, int flags = SectionDefault ) const; 00502 #ifndef QT_NO_REGEXP 00503 QString section( const QRegExp ®, int start, int end = 0xffffffff, int flags = SectionDefault ) const; 00504 #endif 00505 00506 QString left( uint len ) const; 00507 QString right( uint len ) const; 00508 QString mid( uint index, uint len=0xffffffff) const; 00509 00510 QString leftJustify( uint width, QChar fill=' ', bool trunc=FALSE)const; 00511 QString rightJustify( uint width, QChar fill=' ',bool trunc=FALSE)const; 00512 00513 QString lower() const; 00514 QString upper() const; 00515 00516 QString stripWhiteSpace() const; 00517 QString simplifyWhiteSpace() const; 00518 00519 QString &insert( uint index, const QString & ); 00520 #ifndef QT_NO_CAST_ASCII 00521 QString &insert( uint index, const QByteArray & ); 00522 QString &insert( uint index, const char * ); 00523 #endif 00524 QString &insert( uint index, const QChar*, uint len ); 00525 QString &insert( uint index, QChar ); 00526 QString &insert( uint index, char c ) { return insert(index,QChar(c)); } 00527 QString &append( char ); 00528 QString &append( QChar ); 00529 QString &append( const QString & ); 00530 #ifndef QT_NO_CAST_ASCII 00531 QString &append( const QByteArray & ); 00532 QString &append( const char * ); 00533 #endif 00534 #if !defined(QT_NO_STL) && !defined(QT_NO_CAST_ASCII) 00535 QString &append( const std::string& ); 00536 #endif 00537 QString &prepend( char ); 00538 QString &prepend( QChar ); 00539 QString &prepend( const QString & ); 00540 #ifndef QT_NO_CAST_ASCII 00541 QString &prepend( const QByteArray & ); 00542 QString &prepend( const char * ); 00543 #endif 00544 #if !defined(QT_NO_STL) && !defined(QT_NO_CAST_ASCII) 00545 QString &prepend( const std::string& ); 00546 #endif 00547 QString &remove( uint index, uint len ); 00548 #if defined(Q_QDOC) 00549 QString &remove( const QString & str, bool cs = TRUE ); 00550 #else 00551 // ### Qt 4.0: merge these two into one, and remove Q_QDOC hack 00552 QString &remove( const QString & ); 00553 QString &remove( const QString &, bool cs ); 00554 #endif 00555 QString &remove( QChar c ); 00556 QString &remove( char c ) 00557 { return remove( QChar(c) ); } 00558 #ifndef QT_NO_CAST_ASCII 00559 QString &remove( const char * ); 00560 #endif 00561 #ifndef QT_NO_REGEXP 00562 QString &remove( const QRegExp & ); 00563 #endif 00564 QString &replace( uint index, uint len, const QString & ); 00565 QString &replace( uint index, uint len, const QChar*, uint clen ); 00566 QString &replace( uint index, uint len, QChar ); 00567 QString &replace( uint index, uint len, char c ) 00568 { return replace( index, len, QChar(c) ); } 00569 #if defined(Q_QDOC) 00570 QString &replace( QChar c, const QString & after, bool cs = TRUE ); 00571 QString &replace( char c, const QString & after, bool cs = TRUE ); 00572 QString &replace( const QString & before, const QString & after, 00573 bool cs = TRUE ); 00574 #else 00575 // ### Qt 4.0: merge these two into one, and remove Q_QDOC hack 00576 QString &replace( QChar c, const QString & ); 00577 QString &replace( QChar c, const QString &, bool ); 00578 00579 // ### Qt 4.0: merge these two into one, and remove Q_QDOC hack 00580 QString &replace( char c, const QString & after ) 00581 { return replace( QChar(c), after, TRUE ); } 00582 QString &replace( char c, const QString & after, bool cs ) 00583 { return replace( QChar(c), after, cs ); } 00584 00585 // ### Qt 4.0: merge these two into one, and remove Q_QDOC hack 00586 QString &replace( const QString &, const QString & ); 00587 QString &replace( const QString &, const QString &, bool ); 00588 #endif 00589 #ifndef QT_NO_REGEXP_CAPTURE 00590 QString &replace( const QRegExp &, const QString & ); 00591 #endif 00592 QString &replace( QChar, QChar ); 00593 00594 short toShort( bool *ok=0, int base=10 ) const; 00595 ushort toUShort( bool *ok=0, int base=10 ) const; 00596 int toInt( bool *ok=0, int base=10 ) const; 00597 uint toUInt( bool *ok=0, int base=10 ) const; 00598 long toLong( bool *ok=0, int base=10 ) const; 00599 ulong toULong( bool *ok=0, int base=10 ) const; 00600 Q_LLONG toLongLong( bool *ok=0, int base=10 ) const; 00601 Q_ULLONG toULongLong( bool *ok=0, int base=10 ) const; 00602 float toFloat( bool *ok=0 ) const; 00603 double toDouble( bool *ok=0 ) const; 00604 00605 QString &setNum( short, int base=10 ); 00606 QString &setNum( ushort, int base=10 ); 00607 QString &setNum( int, int base=10 ); 00608 QString &setNum( uint, int base=10 ); 00609 QString &setNum( long, int base=10 ); 00610 QString &setNum( ulong, int base=10 ); 00611 QString &setNum( Q_LLONG, int base=10 ); 00612 QString &setNum( Q_ULLONG, int base=10 ); 00613 QString &setNum( float, char f='g', int prec=6 ); 00614 QString &setNum( double, char f='g', int prec=6 ); 00615 00616 static QString number( long, int base=10 ); 00617 static QString number( ulong, int base=10); 00618 static QString number( Q_LLONG, int base=10 ); 00619 static QString number( Q_ULLONG, int base=10); 00620 static QString number( int, int base=10 ); 00621 static QString number( uint, int base=10); 00622 static QString number( double, char f='g', int prec=6 ); 00623 00624 void setExpand( uint index, QChar c ); 00625 00626 QString &operator+=( const QString &str ); 00627 #ifndef QT_NO_CAST_ASCII 00628 QString &operator+=( const QByteArray &str ); 00629 QString &operator+=( const char *str ); 00630 #endif 00631 #if !defined(QT_NO_STL) && !defined(QT_NO_CAST_ASCII) 00632 QString &operator+=( const std::string& ); 00633 #endif 00634 QString &operator+=( QChar c ); 00635 QString &operator+=( char c ); 00636 00637 QChar at( uint i ) const 00638 { return i < d->len ? d->unicode[i] : QChar::null; } 00639 QChar operator[]( int i ) const { return at((uint)i); } 00640 QCharRef at( uint i ); 00641 QCharRef operator[]( int i ); 00642 00643 QChar constref(uint i) const 00644 { return at(i); } 00645 QChar& ref(uint i) 00646 { // Optimized for easy-inlining by simple compilers. 00647 if ( d->count != 1 || i >= d->len ) 00648 subat( i ); 00649 d->setDirty(); 00650 return d->unicode[i]; 00651 } 00652 00653 const QChar* unicode() const { return d->unicode; } 00654 const char* ascii() const; 00655 static QString fromAscii(const char*, int len=-1); 00656 const char* latin1() const; 00657 static QString fromLatin1(const char*, int len=-1); 00658 QCString utf8() const; 00659 static QString fromUtf8(const char*, int len=-1); 00660 QCString local8Bit() const; 00661 static QString fromLocal8Bit(const char*, int len=-1); 00662 bool operator!() const; 00663 #ifndef QT_NO_ASCII_CAST 00664 operator const char *() const { return ascii(); } 00665 #endif 00666 #ifndef QT_NO_STL 00667 operator std::string() const { return ascii() ? ascii() : ""; } 00668 #endif 00669 00670 static QString fromUcs2( const unsigned short *ucs2 ); 00671 const unsigned short *ucs2() const; 00672 00673 QString &setUnicode( const QChar* unicode, uint len ); 00674 QString &setUnicodeCodes( const ushort* unicode_as_ushorts, uint len ); 00675 QString &setAscii( const char*, int len=-1 ); 00676 QString &setLatin1( const char*, int len=-1 ); 00677 00678 int compare( const QString& s ) const; 00679 static int compare( const QString& s1, const QString& s2 ) 00680 { return s1.compare( s2 ); } 00681 00682 int localeAwareCompare( const QString& s ) const; 00683 static int localeAwareCompare( const QString& s1, const QString& s2 ) 00684 { return s1.localeAwareCompare( s2 ); } 00685 00686 #ifndef QT_NO_DATASTREAM 00687 friend Q_EXPORT QDataStream &operator>>( QDataStream &, QString & ); 00688 #endif 00689 00690 void compose(); 00691 00692 #ifndef QT_NO_COMPAT 00693 const char* data() const { return ascii(); } 00694 #endif 00695 00696 #if defined(Q_QDOC) 00697 bool startsWith( const QString& str, bool cs = TRUE ) const; 00698 bool endsWith( const QString& str, bool cs = TRUE ) const; 00699 #else 00700 // ### Qt 4.0: merge these two into one, and remove Q_QDOC hack 00701 bool startsWith( const QString& str ) const; 00702 bool startsWith( const QString& str, bool cs ) const; 00703 00704 // ### Qt 4.0: merge these two into one, and remove Q_QDOC hack 00705 bool endsWith( const QString& str ) const; 00706 bool endsWith( const QString& str, bool cs ) const; 00707 #endif 00708 00709 void setLength( uint newLength ); 00710 00711 uint capacity() const; 00712 void reserve( uint minCapacity ); 00713 void squeeze(); 00714 00715 bool simpleText() const { if ( !d->issimpletext ) checkSimpleText(); return (bool)d->issimpletext; } 00716 bool isRightToLeft() const; 00717 00718 00719 private: 00720 QString( int size, bool /* dummy */ ); // allocate size incl. \0 00721 00722 void deref(); 00723 void real_detach(); 00724 void subat( uint ); 00725 QString multiArg( int numArgs, const QString& a1, const QString& a2, 00726 const QString& a3 = QString::null, 00727 const QString& a4 = QString::null ) const; 00728 00729 void checkSimpleText() const; 00730 void grow( uint newLength ); 00731 #ifndef QT_NO_CAST_ASCII 00732 QString &insertHelper( uint index, const char *s, uint len=UINT_MAX ); 00733 QString &operatorPlusEqHelper( const char *s, uint len2=UINT_MAX ); 00734 #endif 00735 00736 static QChar* latin1ToUnicode( const char*, uint * len, uint maxlen=(uint)-1 ); 00737 static QChar* latin1ToUnicode( const QByteArray&, uint * len ); 00738 static char* unicodeToLatin1( const QChar*, uint len ); 00739 00740 QStringData *d; 00741 static QStringData* shared_null; 00742 static QStringData* makeSharedNull(); 00743 00744 friend class QConstString; 00745 friend class QTextStream; 00746 QString( QStringData* dd, bool /* dummy */ ) : d(dd) { } 00747 00748 // needed for QDeepCopy 00749 void detach(); 00750 friend class QDeepCopy<QString>; 00751 }; 00752 00753 class Q_EXPORT QCharRef { 00754 friend class QString; 00755 QString& s; 00756 uint p; 00757 QCharRef(QString* str, uint pos) : s(*str), p(pos) { } 00758 00759 public: 00760 // most QChar operations repeated here 00761 00762 // all this is not documented: We just say "like QChar" and let it be. 00763 #ifndef Q_QDOC 00764 ushort unicode() const { return s.constref(p).unicode(); } 00765 char latin1() const { return s.constref(p).latin1(); } 00766 00767 // An operator= for each QChar cast constructors 00768 QCharRef operator=(char c ) { s.ref(p)=c; return *this; } 00769 QCharRef operator=(uchar c ) { s.ref(p)=c; return *this; } 00770 QCharRef operator=(QChar c ) { s.ref(p)=c; return *this; } 00771 QCharRef operator=(const QCharRef& c ) { s.ref(p)=c.unicode(); return *this; } 00772 QCharRef operator=(ushort rc ) { s.ref(p)=rc; return *this; } 00773 QCharRef operator=(short rc ) { s.ref(p)=rc; return *this; } 00774 QCharRef operator=(uint rc ) { s.ref(p)=rc; return *this; } 00775 QCharRef operator=(int rc ) { s.ref(p)=rc; return *this; } 00776 00777 operator QChar () const { return s.constref(p); } 00778 00779 // each function... 00780 bool isNull() const { return unicode()==0; } 00781 bool isPrint() const { return s.constref(p).isPrint(); } 00782 bool isPunct() const { return s.constref(p).isPunct(); } 00783 bool isSpace() const { return s.constref(p).isSpace(); } 00784 bool isMark() const { return s.constref(p).isMark(); } 00785 bool isLetter() const { return s.constref(p).isLetter(); } 00786 bool isNumber() const { return s.constref(p).isNumber(); } 00787 bool isLetterOrNumber() { return s.constref(p).isLetterOrNumber(); } 00788 bool isDigit() const { return s.constref(p).isDigit(); } 00789 00790 int digitValue() const { return s.constref(p).digitValue(); } 00791 QChar lower() const { return s.constref(p).lower(); } 00792 QChar upper() const { return s.constref(p).upper(); } 00793 00794 QChar::Category category() const { return s.constref(p).category(); } 00795 QChar::Direction direction() const { return s.constref(p).direction(); } 00796 QChar::Joining joining() const { return s.constref(p).joining(); } 00797 bool mirrored() const { return s.constref(p).mirrored(); } 00798 QChar mirroredChar() const { return s.constref(p).mirroredChar(); } 00799 const QString &decomposition() const { return s.constref(p).decomposition(); } 00800 QChar::Decomposition decompositionTag() const { return s.constref(p).decompositionTag(); } 00801 unsigned char combiningClass() const { return s.constref(p).combiningClass(); } 00802 00803 // Not the non-const ones of these. 00804 uchar cell() const { return s.constref(p).cell(); } 00805 uchar row() const { return s.constref(p).row(); } 00806 #endif 00807 }; 00808 00809 inline QCharRef QString::at( uint i ) { return QCharRef(this,i); } 00810 inline QCharRef QString::operator[]( int i ) { return at((uint)i); } 00811 00812 00813 class Q_EXPORT QConstString : private QString { 00814 public: 00815 QConstString( const QChar* unicode, uint length ); 00816 ~QConstString(); 00817 const QString& string() const { return *this; } 00818 }; 00819 00820 00821 /***************************************************************************** 00822 QString stream functions 00823 *****************************************************************************/ 00824 #ifndef QT_NO_DATASTREAM 00825 Q_EXPORT QDataStream &operator<<( QDataStream &, const QString & ); 00826 Q_EXPORT QDataStream &operator>>( QDataStream &, QString & ); 00827 #endif 00828 00829 /***************************************************************************** 00830 QString inline functions 00831 *****************************************************************************/ 00832 00833 // These two move code into makeSharedNull() and deletesData() 00834 // to improve cache-coherence (and reduce code bloat), while 00835 // keeping the common cases fast. 00836 // 00837 // No safe way to pre-init shared_null on ALL compilers/linkers. 00838 inline QString::QString() : 00839 d(shared_null ? shared_null : makeSharedNull()) 00840 { 00841 d->ref(); 00842 } 00843 // 00844 inline QString::~QString() 00845 { 00846 if ( d->deref() ) { 00847 if ( d != shared_null ) 00848 d->deleteSelf(); 00849 } 00850 } 00851 00852 // needed for QDeepCopy 00853 inline void QString::detach() 00854 { real_detach(); } 00855 00856 inline QString QString::section( QChar sep, int start, int end, int flags ) const 00857 { return section(QString(sep), start, end, flags); } 00858 00859 inline QString QString::section( char sep, int start, int end, int flags ) const 00860 { return section(QChar(sep), start, end, flags); } 00861 00862 #ifndef QT_NO_CAST_ASCII 00863 inline QString QString::section( const char *in_sep, int start, int end, int flags ) const 00864 { return section(QString(in_sep), start, end, flags); } 00865 #endif 00866 00867 inline QString &QString::operator=( QChar c ) 00868 { *this = QString(c); return *this; } 00869 00870 inline QString &QString::operator=( char c ) 00871 { *this = QString(QChar(c)); return *this; } 00872 00873 inline bool QString::isNull() const 00874 { return unicode() == 0; } 00875 00876 inline bool QString::operator!() const 00877 { return isNull(); } 00878 00879 inline uint QString::length() const 00880 { return d->len; } 00881 00882 inline uint QString::capacity() const 00883 { return d->maxl; } 00884 00885 inline bool QString::isEmpty() const 00886 { return length() == 0; } 00887 00888 inline QString QString::copy() const 00889 { return QString( *this ); } 00890 00891 #ifndef QT_NO_CAST_ASCII 00892 inline QString &QString::insert( uint index, const char *s ) 00893 { return insertHelper( index, s ); } 00894 00895 inline QString &QString::insert( uint index, const QByteArray &s ) 00896 { 00897 int pos = s.find( 0 ); 00898 return insertHelper( index, s, pos==-1 ? s.size() : pos ); 00899 } 00900 #endif 00901 00902 inline QString &QString::prepend( const QString & s ) 00903 { return insert(0,s); } 00904 00905 inline QString &QString::prepend( QChar c ) 00906 { return insert(0,c); } 00907 00908 inline QString &QString::prepend( char c ) 00909 { return insert(0,c); } 00910 00911 #ifndef QT_NO_CAST_ASCII 00912 inline QString &QString::prepend( const QByteArray & s ) 00913 { return insert(0,s); } 00914 #endif 00915 00916 #ifndef QT_NO_CAST_ASCII 00917 inline QString &QString::operator+=( const QByteArray &s ) 00918 { 00919 int pos = s.find( 0 ); 00920 return operatorPlusEqHelper( s, pos==-1 ? s.size() : pos ); 00921 } 00922 #endif 00923 00924 inline QString &QString::append( const QString & s ) 00925 { return operator+=(s); } 00926 00927 #ifndef QT_NO_CAST_ASCII 00928 inline QString &QString::append( const QByteArray &s ) 00929 { return operator+=(s); } 00930 00931 inline QString &QString::append( const char * s ) 00932 { return operator+=(s); } 00933 #endif 00934 00935 inline QString &QString::append( QChar c ) 00936 { return operator+=(c); } 00937 00938 inline QString &QString::append( char c ) 00939 { return operator+=(c); } 00940 00941 #ifndef QT_NO_STL 00942 inline QString &QString::operator=( const std::string& str ) 00943 { return operator=(str.c_str()); } 00944 #ifndef QT_NO_CAST_ASCII 00945 inline QString &QString::operator+=( const std::string& s ) 00946 { return operator+=(s.c_str()); } 00947 inline QString &QString::append( const std::string& s ) 00948 { return operator+=(s); } 00949 inline QString &QString::prepend( const std::string& s ) 00950 { return insert(0, s); } 00951 #endif 00952 #endif 00953 00954 inline QString &QString::setNum( short n, int base ) 00955 { return setNum((Q_LLONG)n, base); } 00956 00957 inline QString &QString::setNum( ushort n, int base ) 00958 { return setNum((Q_ULLONG)n, base); } 00959 00960 inline QString &QString::setNum( int n, int base ) 00961 { return setNum((Q_LLONG)n, base); } 00962 00963 inline QString &QString::setNum( uint n, int base ) 00964 { return setNum((Q_ULLONG)n, base); } 00965 00966 inline QString &QString::setNum( float n, char f, int prec ) 00967 { return setNum((double)n,f,prec); } 00968 00969 inline QString QString::arg( int a, int fieldWidth, int base ) const 00970 { return arg( (Q_LLONG)a, fieldWidth, base ); } 00971 00972 inline QString QString::arg( uint a, int fieldWidth, int base ) const 00973 { return arg( (Q_ULLONG)a, fieldWidth, base ); } 00974 00975 inline QString QString::arg( short a, int fieldWidth, int base ) const 00976 { return arg( (Q_LLONG)a, fieldWidth, base ); } 00977 00978 inline QString QString::arg( ushort a, int fieldWidth, int base ) const 00979 { return arg( (Q_ULLONG)a, fieldWidth, base ); } 00980 00981 inline QString QString::arg( const QString& a1, const QString& a2 ) const { 00982 return multiArg( 2, a1, a2 ); 00983 } 00984 00985 inline QString QString::arg( const QString& a1, const QString& a2, 00986 const QString& a3 ) const { 00987 return multiArg( 3, a1, a2, a3 ); 00988 } 00989 00990 inline QString QString::arg( const QString& a1, const QString& a2, 00991 const QString& a3, const QString& a4 ) const { 00992 return multiArg( 4, a1, a2, a3, a4 ); 00993 } 00994 00995 inline int QString::find( char c, int index, bool cs ) const 00996 { return find(QChar(c), index, cs); } 00997 00998 inline int QString::findRev( char c, int index, bool cs ) const 00999 { return findRev( QChar(c), index, cs ); } 01000 01001 #ifndef QT_NO_CAST_ASCII 01002 inline int QString::find( const char* str, int index ) const 01003 { return find(QString::fromAscii(str), index); } 01004 01005 inline int QString::findRev( const char* str, int index ) const 01006 { return findRev(QString::fromAscii(str), index); } 01007 #endif 01008 01009 01010 /***************************************************************************** 01011 QString non-member operators 01012 *****************************************************************************/ 01013 01014 Q_EXPORT bool operator!=( const QString &s1, const QString &s2 ); 01015 Q_EXPORT bool operator<( const QString &s1, const QString &s2 ); 01016 Q_EXPORT bool operator<=( const QString &s1, const QString &s2 ); 01017 Q_EXPORT bool operator==( const QString &s1, const QString &s2 ); 01018 Q_EXPORT bool operator>( const QString &s1, const QString &s2 ); 01019 Q_EXPORT bool operator>=( const QString &s1, const QString &s2 ); 01020 #ifndef QT_NO_CAST_ASCII 01021 Q_EXPORT bool operator!=( const QString &s1, const char *s2 ); 01022 Q_EXPORT bool operator<( const QString &s1, const char *s2 ); 01023 Q_EXPORT bool operator<=( const QString &s1, const char *s2 ); 01024 Q_EXPORT bool operator==( const QString &s1, const char *s2 ); 01025 Q_EXPORT bool operator>( const QString &s1, const char *s2 ); 01026 Q_EXPORT bool operator>=( const QString &s1, const char *s2 ); 01027 Q_EXPORT bool operator!=( const char *s1, const QString &s2 ); 01028 Q_EXPORT bool operator<( const char *s1, const QString &s2 ); 01029 Q_EXPORT bool operator<=( const char *s1, const QString &s2 ); 01030 Q_EXPORT bool operator==( const char *s1, const QString &s2 ); 01031 //Q_EXPORT bool operator>( const char *s1, const QString &s2 ); // MSVC++ 01032 Q_EXPORT bool operator>=( const char *s1, const QString &s2 ); 01033 #endif 01034 01035 Q_EXPORT inline const QString operator+( const QString &s1, const QString &s2 ) 01036 { 01037 QString tmp( s1 ); 01038 tmp += s2; 01039 return tmp; 01040 } 01041 01042 #ifndef QT_NO_CAST_ASCII 01043 Q_EXPORT inline const QString operator+( const QString &s1, const char *s2 ) 01044 { 01045 QString tmp( s1 ); 01046 tmp += QString::fromAscii(s2); 01047 return tmp; 01048 } 01049 01050 Q_EXPORT inline const QString operator+( const char *s1, const QString &s2 ) 01051 { 01052 QString tmp = QString::fromAscii( s1 ); 01053 tmp += s2; 01054 return tmp; 01055 } 01056 #endif 01057 01058 Q_EXPORT inline const QString operator+( const QString &s1, QChar c2 ) 01059 { 01060 QString tmp( s1 ); 01061 tmp += c2; 01062 return tmp; 01063 } 01064 01065 Q_EXPORT inline const QString operator+( const QString &s1, char c2 ) 01066 { 01067 QString tmp( s1 ); 01068 tmp += c2; 01069 return tmp; 01070 } 01071 01072 Q_EXPORT inline const QString operator+( QChar c1, const QString &s2 ) 01073 { 01074 QString tmp; 01075 tmp += c1; 01076 tmp += s2; 01077 return tmp; 01078 } 01079 01080 Q_EXPORT inline const QString operator+( char c1, const QString &s2 ) 01081 { 01082 QString tmp; 01083 tmp += c1; 01084 tmp += s2; 01085 return tmp; 01086 } 01087 01088 #ifndef QT_NO_STL 01089 Q_EXPORT inline const QString operator+(const QString& s1, const std::string& s2) 01090 { 01091 return s1 + QString(s2); 01092 } 01093 01094 Q_EXPORT inline const QString operator+(const std::string& s1, const QString& s2) 01095 { 01096 QString tmp(s2); 01097 return QString(tmp.prepend(s1)); 01098 } 01099 #endif 01100 01101 01102 #if defined(Q_OS_WIN32) 01103 extern Q_EXPORT QString qt_winQString(void*); 01104 extern Q_EXPORT const void* qt_winTchar(const QString& str, bool addnul); 01105 extern Q_EXPORT void* qt_winTchar_new(const QString& str); 01106 extern Q_EXPORT QCString qt_winQString2MB( const QString& s, int len=-1 ); 01107 extern Q_EXPORT QString qt_winMB2QString( const char* mb, int len=-1 ); 01108 #endif 01109 01110 #define Q_DEFINED_QSTRING 01111 #include "qwinexport.h" 01112 #endif // QSTRING_H