Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

qstring.h

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

Generated on Sat Nov 5 16:18:26 2005 for OPIE by  doxygen 1.4.2