Orb/Doxygen/qtools/qstring.h
changeset 0 42188c7ea2d9
equal deleted inserted replaced
-1:000000000000 0:42188c7ea2d9
       
     1 /****************************************************************************
       
     2 ** 
       
     3 **
       
     4 ** Definition of the QString class, and related Unicode
       
     5 ** functions.
       
     6 **
       
     7 ** Created : 920609
       
     8 **
       
     9 ** Copyright (C) 1992-2000 Trolltech AS.  All rights reserved.
       
    10 **
       
    11 ** This file is part of the tools module of the Qt GUI Toolkit.
       
    12 **
       
    13 ** This file may be distributed under the terms of the Q Public License
       
    14 ** as defined by Trolltech AS of Norway and appearing in the file
       
    15 ** LICENSE.QPL included in the packaging of this file.
       
    16 **
       
    17 ** This file may be distributed and/or modified under the terms of the
       
    18 ** GNU General Public License version 2 as published by the Free Software
       
    19 ** Foundation and appearing in the file LICENSE.GPL included in the
       
    20 ** packaging of this file.
       
    21 **
       
    22 ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
       
    23 ** licenses may use this file in accordance with the Qt Commercial License
       
    24 ** Agreement provided with the Software.
       
    25 **
       
    26 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
       
    27 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
       
    28 **
       
    29 ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
       
    30 **   information about Qt Commercial License Agreements.
       
    31 ** See http://www.trolltech.com/qpl/ for QPL licensing information.
       
    32 ** See http://www.trolltech.com/gpl/ for GPL licensing information.
       
    33 **
       
    34 ** Contact info@trolltech.com if any conditions of this licensing are
       
    35 ** not clear to you.
       
    36 **
       
    37 **********************************************************************/
       
    38 
       
    39 #ifndef QSTRING_H
       
    40 #define QSTRING_H
       
    41 
       
    42 #ifndef QT_H
       
    43 #include "qcstring.h"
       
    44 #endif // QT_H
       
    45 
       
    46 
       
    47 /*****************************************************************************
       
    48   QString class
       
    49  *****************************************************************************/
       
    50 
       
    51 class QRegExp;
       
    52 class QString;
       
    53 class QCharRef;
       
    54 
       
    55 class Q_EXPORT Q_PACKED QChar {
       
    56 public:
       
    57     QChar();
       
    58     QChar( char c );
       
    59     QChar( uchar c );
       
    60     QChar( uchar c, uchar r );
       
    61     QChar( const QChar& c );
       
    62     QChar( ushort rc );
       
    63     QChar( short rc );
       
    64     QChar( uint rc );
       
    65     QChar( int rc );
       
    66 
       
    67     QT_STATIC_CONST QChar null;            // 0000
       
    68     QT_STATIC_CONST QChar replacement;     // FFFD
       
    69     QT_STATIC_CONST QChar byteOrderMark;     // FEFF
       
    70     QT_STATIC_CONST QChar byteOrderSwapped;     // FFFE
       
    71     QT_STATIC_CONST QChar nbsp;            // 00A0
       
    72 
       
    73     // Unicode information
       
    74 
       
    75     enum Category
       
    76     {
       
    77 	NoCategory,
       
    78 
       
    79 	Mark_NonSpacing,	  //   Mn
       
    80 	Mark_SpacingCombining,	  //   Mc
       
    81 	Mark_Enclosing,		  //   Me
       
    82 
       
    83 	Number_DecimalDigit,	  //   Nd
       
    84 	Number_Letter,		  //   Nl
       
    85 	Number_Other,		  //   No
       
    86 
       
    87 	Separator_Space,	  //   Zs
       
    88 	Separator_Line,		  //   Zl
       
    89 	Separator_Paragraph,	  //   Zp
       
    90 
       
    91 	Other_Control,		  //   Cc
       
    92 	Other_Format,		  //   Cf
       
    93 	Other_Surrogate,	  //   Cs
       
    94 	Other_PrivateUse,	  //   Co
       
    95 	Other_NotAssigned,	  //   Cn
       
    96 
       
    97 	Letter_Uppercase,	  //   Lu
       
    98 	Letter_Lowercase,	  //   Ll
       
    99 	Letter_Titlecase,	  //   Lt
       
   100 	Letter_Modifier,	  //   Lm
       
   101 	Letter_Other,		  //   Lo
       
   102 
       
   103 	Punctuation_Connector,	  //   Pc
       
   104 	Punctuation_Dask,	  //   Pd
       
   105 	Punctuation_Open,	  //   Ps
       
   106 	Punctuation_Close,	  //   Pe
       
   107 	Punctuation_InitialQuote, //   Pi
       
   108 	Punctuation_FinalQuote,	  //   Pf
       
   109 	Punctuation_Other,	  //   Po
       
   110 
       
   111 	Symbol_Math,		  //   Sm
       
   112 	Symbol_Currency,	  //   Sc
       
   113 	Symbol_Modifier,	  //   Sk
       
   114 	Symbol_Other		  //   So
       
   115     };
       
   116 
       
   117     enum Direction
       
   118     {
       
   119 	DirL, DirR, DirEN, DirES, DirET, DirAN, DirCS, DirB, DirS, DirWS, DirON,
       
   120 	DirLRE, DirLRO, DirAL, DirRLE, DirRLO, DirPDF, DirNSM, DirBN
       
   121     };
       
   122 
       
   123     enum Decomposition
       
   124     {
       
   125         Single, Canonical, Font, NoBreak, Initial, Medial,
       
   126         Final, Isolated, Circle, Super, Sub, Vertical,
       
   127         Wide, Narrow, Small, Square, Compat, Fraction
       
   128     };
       
   129 
       
   130     enum Joining
       
   131     {
       
   132 	OtherJoining, Dual, Right, Center
       
   133     };
       
   134 
       
   135     // ****** WHEN ADDING FUNCTIONS, CONSIDER ADDING TO QCharRef TOO
       
   136 
       
   137     int digitValue() const;
       
   138     QChar lower() const;
       
   139     QChar upper() const;
       
   140 
       
   141     Category category() const;
       
   142     Direction direction() const;
       
   143     Joining joining() const;
       
   144     bool mirrored() const;
       
   145     QChar mirroredChar() const;
       
   146     QString decomposition() const;
       
   147     Decomposition decompositionTag() const;
       
   148 
       
   149     char latin1() const { return rw ? 0 : cl; }
       
   150     ushort unicode() const { return (rw << 8) | cl; }
       
   151 #ifndef QT_NO_CAST_ASCII
       
   152     // like all ifdef'd code this is undocumented
       
   153     operator char() const { return latin1(); }
       
   154 #endif
       
   155 
       
   156     bool isNull() const { return unicode()==0; }
       
   157     bool isPrint() const;
       
   158     bool isPunct() const;
       
   159     bool isSpace() const;
       
   160     bool isMark() const;
       
   161     bool isLetter() const;
       
   162     bool isNumber() const;
       
   163     bool isLetterOrNumber() const;
       
   164     bool isDigit() const;
       
   165 
       
   166     uchar& cell() { return cl; }
       
   167     uchar& row() { return rw; }
       
   168     uchar cell() const { return cl; }
       
   169     uchar row() const { return rw; }
       
   170 
       
   171     static bool networkOrdered() { return (int)net_ordered == 1; }
       
   172 
       
   173     friend inline int operator==( char ch, QChar c );
       
   174     friend inline int operator==( QChar c, char ch );
       
   175     friend inline int operator==( QChar c1, QChar c2 );
       
   176     friend inline int operator!=( QChar c1, QChar c2 );
       
   177     friend inline int operator!=( char ch, QChar c );
       
   178     friend inline int operator!=( QChar c, char ch );
       
   179     friend inline int operator<=( QChar c, char ch );
       
   180     friend inline int operator<=( char ch, QChar c );
       
   181     friend inline int operator<=( QChar c1, QChar c2 );
       
   182 
       
   183 private:
       
   184 #if defined(_WS_X11_) || defined(_OS_WIN32_BYTESWAP_) || defined( _WS_QWS_ )
       
   185     // XChar2b on X11, ushort on _OS_WIN32_BYTESWAP_
       
   186     //### QWS must be defined on a platform by platform basis
       
   187     uchar rw;
       
   188     uchar cl;
       
   189 #if defined(QT_QSTRING_UCS_4)
       
   190     ushort grp;
       
   191 #endif
       
   192     enum { net_ordered = 1 };
       
   193 #else
       
   194     // ushort on _OS_WIN32_
       
   195     uchar cl;
       
   196     uchar rw;
       
   197 #if defined(QT_QSTRING_UCS_4)
       
   198     ushort grp;
       
   199 #endif
       
   200     enum { net_ordered = 0 };
       
   201 #endif
       
   202 };
       
   203 
       
   204 inline QChar::QChar()
       
   205 {
       
   206     rw = 0; cl = 0;
       
   207 #ifdef QT_QSTRING_UCS_4
       
   208     grp = 0;
       
   209 #endif
       
   210 }
       
   211 inline QChar::QChar( char c )
       
   212 {
       
   213     rw = 0; cl = (uchar)c;
       
   214 #ifdef QT_QSTRING_UCS_4
       
   215     grp = 0;
       
   216 #endif
       
   217 }
       
   218 inline QChar::QChar( uchar c )
       
   219 {
       
   220     rw = 0; cl = c;
       
   221 #ifdef QT_QSTRING_UCS_4
       
   222     grp = 0;
       
   223 #endif
       
   224 }
       
   225 inline QChar::QChar( uchar c, uchar r )
       
   226 {
       
   227     rw = r; cl = c;
       
   228 #ifdef QT_QSTRING_UCS_4
       
   229     grp = 0;
       
   230 #endif
       
   231 }
       
   232 inline QChar::QChar( const QChar& c )
       
   233 {
       
   234     rw = c.rw; cl = c.cl;
       
   235 #ifdef QT_QSTRING_UCS_4
       
   236     grp = 0;
       
   237 #endif
       
   238 }
       
   239 inline QChar::QChar( ushort rc )
       
   240 {
       
   241     rw = (uchar)((rc>>8)&0xff); cl = (uchar)(rc&0xff);
       
   242 #ifdef QT_QSTRING_UCS_4
       
   243     grp = 0;
       
   244 #endif
       
   245 }
       
   246 inline QChar::QChar( short rc )
       
   247 {
       
   248     rw = (uchar)((rc>>8)&0xff); cl = (uchar)(rc&0xff);
       
   249 #ifdef QT_QSTRING_UCS_4
       
   250     grp = 0;
       
   251 #endif
       
   252 }
       
   253 inline QChar::QChar( uint rc )
       
   254 {
       
   255     rw = (uchar)((rc>>8)&0xff); cl = (uchar)(rc&0xff);
       
   256 #ifdef QT_QSTRING_UCS_4
       
   257     grp = 0;
       
   258 #endif
       
   259 }
       
   260 inline QChar::QChar( int rc )
       
   261 {
       
   262     rw = (uchar)((rc>>8)&0xff); cl = (uchar)(rc&0xff);
       
   263 #ifdef QT_QSTRING_UCS_4
       
   264     grp = 0;
       
   265 #endif
       
   266 }
       
   267 
       
   268 
       
   269 inline int operator==( char ch, QChar c )
       
   270 {
       
   271     return ch == c.cl && !c.rw;
       
   272 }
       
   273 
       
   274 inline int operator==( QChar c, char ch )
       
   275 {
       
   276     return ch == c.cl && !c.rw;
       
   277 }
       
   278 
       
   279 inline int operator==( QChar c1, QChar c2 )
       
   280 {
       
   281     return c1.cl == c2.cl
       
   282 	&& c1.rw == c2.rw;
       
   283 }
       
   284 
       
   285 inline int operator!=( QChar c1, QChar c2 )
       
   286 {
       
   287     return c1.cl != c2.cl
       
   288 	|| c1.rw != c2.rw;
       
   289 }
       
   290 
       
   291 inline int operator!=( char ch, QChar c )
       
   292 {
       
   293     return ch != c.cl || c.rw;
       
   294 }
       
   295 
       
   296 inline int operator!=( QChar c, char ch )
       
   297 {
       
   298     return ch != c.cl || c.rw;
       
   299 }
       
   300 
       
   301 inline int operator<=( QChar c, char ch )
       
   302 {
       
   303     return !(ch < c.cl || c.rw);
       
   304 }
       
   305 
       
   306 inline int operator<=( char ch, QChar c )
       
   307 {
       
   308     return ch <= c.cl || c.rw;
       
   309 }
       
   310 
       
   311 inline int operator<=( QChar c1, QChar c2 )
       
   312 {
       
   313     return c1.rw > c2.rw
       
   314 	? FALSE
       
   315 	: c1.rw < c2.rw
       
   316 	    ? TRUE
       
   317 	    : c1.cl <= c2.cl;
       
   318 }
       
   319 
       
   320 inline int operator>=( QChar c, char ch ) { return ch <= c; }
       
   321 inline int operator>=( char ch, QChar c ) { return c <= ch; }
       
   322 inline int operator>=( QChar c1, QChar c2 ) { return c2 <= c1; }
       
   323 inline int operator<( QChar c, char ch ) { return !(ch<=c); }
       
   324 inline int operator<( char ch, QChar c ) { return !(c<=ch); }
       
   325 inline int operator<( QChar c1, QChar c2 ) { return !(c2<=c1); }
       
   326 inline int operator>( QChar c, char ch ) { return !(ch>=c); }
       
   327 inline int operator>( char ch, QChar c ) { return !(c>=ch); }
       
   328 inline int operator>( QChar c1, QChar c2 ) { return !(c2>=c1); }
       
   329 
       
   330 // internal
       
   331 struct Q_EXPORT QStringData : public QShared {
       
   332     QStringData() :
       
   333 	unicode(0), ascii(0), len(0), maxl(0), dirtyascii(0) { ref(); }
       
   334     QStringData(QChar *u, uint l, uint m) :
       
   335 	unicode(u), ascii(0), len(l), maxl(m), dirtyascii(0) { }
       
   336 
       
   337     ~QStringData() { if ( unicode ) delete[] ((char*)unicode);
       
   338                      if ( ascii ) delete[] ascii; }
       
   339 
       
   340     void deleteSelf();
       
   341     QChar *unicode;
       
   342     char *ascii;
       
   343     uint len;
       
   344     uint maxl:30;
       
   345     uint dirtyascii:1;
       
   346 };
       
   347 
       
   348 
       
   349 class Q_EXPORT QString
       
   350 {
       
   351 public:
       
   352     QString();					// make null string
       
   353     QString( QChar );				// one-char string
       
   354     QString( const QString & );			// impl-shared copy
       
   355     QString( const QByteArray& );		// deep copy
       
   356     QString( const QCString& );		        // deep copy
       
   357     QString( const QChar* unicode, uint length ); // deep copy
       
   358 #ifndef QT_NO_CAST_ASCII
       
   359     QString( const char *str );			// deep copy
       
   360 #endif
       
   361     ~QString();
       
   362 
       
   363     QString    &operator=( const QString & );	// impl-shared copy
       
   364 #ifndef QT_NO_CAST_ASCII
       
   365     QString    &operator=( const char * );	// deep copy
       
   366 #endif
       
   367     QString    &operator=( const QCString& );	// deep copy
       
   368     QString    &operator=( QChar c );
       
   369     QString    &operator=( char c );
       
   370 
       
   371     QT_STATIC_CONST QString null;
       
   372 
       
   373     bool	isNull()	const;
       
   374     bool	isEmpty()	const;
       
   375     uint	length()	const;
       
   376     void	truncate( uint pos );
       
   377 
       
   378 #if QT_VERSION >= 300
       
   379 #error "fill() Should return *this, or QChar constructor should take count=1"
       
   380 #endif
       
   381     void	fill( QChar c, int len = -1 );
       
   382 
       
   383     QString	copy()	const;
       
   384 
       
   385     QString arg(long a, int fieldwidth=0, int base=10) const;
       
   386     QString arg(ulong a, int fieldwidth=0, int base=10) const;
       
   387     QString arg(int a, int fieldwidth=0, int base=10) const;
       
   388     QString arg(uint a, int fieldwidth=0, int base=10) const;
       
   389     QString arg(short a, int fieldwidth=0, int base=10) const;
       
   390     QString arg(ushort a, int fieldwidth=0, int base=10) const;
       
   391     QString arg(char a, int fieldwidth=0) const;
       
   392     QString arg(QChar a, int fieldwidth=0) const;
       
   393     QString arg(const QString& a, int fieldwidth=0) const;
       
   394     QString arg(double a, int fieldwidth=0, char fmt='g', int prec=-1) const;
       
   395 
       
   396     QString    &sprintf( const char* format, ... )
       
   397 #if defined(_CC_GNU_) && !defined(__INSURE__)
       
   398 	__attribute__ ((format (printf, 2, 3)))
       
   399 #endif
       
   400 	;
       
   401 
       
   402     int		find( QChar c, int index=0, bool cs=TRUE ) const;
       
   403     int		find( char c, int index=0, bool cs=TRUE ) const;
       
   404     int		find( const QString &str, int index=0, bool cs=TRUE ) const;
       
   405     int		find( const QRegExp &, int index=0 ) const;
       
   406 #ifndef QT_NO_CAST_ASCII
       
   407     int		find( const char* str, int index=0 ) const;
       
   408 #endif
       
   409     int		findRev( QChar c, int index=-1, bool cs=TRUE) const;
       
   410     int		findRev( char c, int index=-1, bool cs=TRUE) const;
       
   411     int		findRev( const QString &str, int index=-1, bool cs=TRUE) const;
       
   412     int		findRev( const QRegExp &, int index=-1 ) const;
       
   413 #ifndef QT_NO_CAST_ASCII
       
   414     int		findRev( const char* str, int index=-1 ) const;
       
   415 #endif
       
   416     int		contains( QChar c, bool cs=TRUE ) const;
       
   417     int		contains( char c, bool cs=TRUE ) const
       
   418 		    { return contains(QChar(c), cs); }
       
   419 #ifndef QT_NO_CAST_ASCII
       
   420     int		contains( const char* str, bool cs=TRUE ) const;
       
   421 #endif
       
   422     int		contains( const QString &str, bool cs=TRUE ) const;
       
   423     int		contains( const QRegExp & ) const;
       
   424 
       
   425     QString	left( uint len )  const;
       
   426     QString	right( uint len ) const;
       
   427     QString	mid( uint index, uint len=0xffffffff) const;
       
   428 
       
   429     QString	leftJustify( uint width, QChar fill=' ', bool trunc=FALSE)const;
       
   430     QString	rightJustify( uint width, QChar fill=' ',bool trunc=FALSE)const;
       
   431 
       
   432     QString	lower() const;
       
   433     QString	upper() const;
       
   434 
       
   435     QString	stripWhiteSpace()	const;
       
   436     QString	simplifyWhiteSpace()	const;
       
   437 
       
   438     QString    &insert( uint index, const QString & );
       
   439     QString    &insert( uint index, const QChar*, uint len );
       
   440     QString    &insert( uint index, QChar );
       
   441     QString    &insert( uint index, char c ) { return insert(index,QChar(c)); }
       
   442     QString    &append( char );
       
   443     QString    &append( QChar );
       
   444     QString    &append( const QString & );
       
   445     QString    &prepend( char );
       
   446     QString    &prepend( QChar );
       
   447     QString    &prepend( const QString & );
       
   448     QString    &remove( uint index, uint len );
       
   449     QString    &replace( uint index, uint len, const QString & );
       
   450     QString    &replace( uint index, uint len, const QChar*, uint clen );
       
   451     QString    &replace( const QRegExp &, const QString & );
       
   452 
       
   453     short	toShort( bool *ok=0, int base=10 )	const;
       
   454     ushort	toUShort( bool *ok=0, int base=10 )	const;
       
   455     int		toInt( bool *ok=0, int base=10 )	const;
       
   456     uint	toUInt( bool *ok=0, int base=10 )	const;
       
   457     long	toLong( bool *ok=0, int base=10 )	const;
       
   458     ulong	toULong( bool *ok=0, int base=10 )	const;
       
   459     float	toFloat( bool *ok=0 )	const;
       
   460     double	toDouble( bool *ok=0 )	const;
       
   461 
       
   462     QString    &setNum( short, int base=10 );
       
   463     QString    &setNum( ushort, int base=10 );
       
   464     QString    &setNum( int, int base=10 );
       
   465     QString    &setNum( uint, int base=10 );
       
   466     QString    &setNum( long, int base=10 );
       
   467     QString    &setNum( ulong, int base=10 );
       
   468     QString    &setNum( float, char f='g', int prec=6 );
       
   469     QString    &setNum( double, char f='g', int prec=6 );
       
   470 
       
   471     static QString number( long, int base=10 );
       
   472     static QString number( ulong, int base=10);
       
   473     static QString number( int, int base=10 );
       
   474     static QString number( uint, int base=10);
       
   475     static QString number( double, char f='g', int prec=6 );
       
   476 
       
   477     void	setExpand( uint index, QChar c );
       
   478 
       
   479     QString    &operator+=( const QString &str );
       
   480     QString    &operator+=( QChar c );
       
   481     QString    &operator+=( char c );
       
   482 
       
   483     // Your compiler is smart enough to use the const one if it can.
       
   484     QChar at( uint i ) const
       
   485 	{ return i<d->len ? d->unicode[i] : QChar::null; }
       
   486     QChar operator[]( int i ) const { return at((uint)i); }
       
   487     QCharRef at( uint i );
       
   488     QCharRef operator[]( int i );
       
   489 
       
   490     QChar constref(uint i) const
       
   491 	{ return at(i); }
       
   492     QChar& ref(uint i)
       
   493 	{ // Optimized for easy-inlining by simple compilers.
       
   494 	    if (d->count!=1 || i>=d->len)
       
   495 		subat(i);
       
   496 	    d->dirtyascii=1;
       
   497 	    return d->unicode[i];
       
   498 	}
       
   499 
       
   500     const QChar* unicode() const { return d->unicode; }
       
   501     const char* ascii() const;
       
   502     const char* latin1() const;
       
   503     static QString fromLatin1(const char*, int len=-1);
       
   504 #ifndef QT_NO_TEXTCODEC
       
   505     QCString utf8() const;
       
   506     static QString fromUtf8(const char*, int len=-1);
       
   507 #endif
       
   508     QCString local8Bit() const;
       
   509     static QString fromLocal8Bit(const char*, int len=-1);
       
   510     bool operator!() const;
       
   511 #ifndef QT_NO_ASCII_CAST
       
   512     operator const char *() const { return latin1(); }
       
   513 #endif
       
   514 
       
   515     QString &setUnicode( const QChar* unicode, uint len );
       
   516     QString &setUnicodeCodes( const ushort* unicode_as_ushorts, uint len );
       
   517     QString &setLatin1( const char*, int len=-1 );
       
   518 
       
   519     int compare( const QString& s ) const;
       
   520     static int compare( const QString& s1, const QString& s2 )
       
   521 	{ return s1.compare(s2); }
       
   522 
       
   523 #ifndef QT_NO_DATASTREAM
       
   524     friend Q_EXPORT QDataStream &operator>>( QDataStream &, QString & );
       
   525 #endif
       
   526     // new functions for BiDi
       
   527     void compose();
       
   528     QChar::Direction basicDirection();
       
   529     QString visual(int index = 0, int len = -1);
       
   530 
       
   531 #ifndef QT_NO_COMPAT
       
   532     const char* data() const { return latin1(); }
       
   533 #endif
       
   534 
       
   535     bool startsWith( const QString& ) const;
       
   536 
       
   537 private:
       
   538     QString( int size, bool dummy );		// allocate size incl. \0
       
   539 
       
   540     void deref();
       
   541     void real_detach();
       
   542     void setLength( uint pos );
       
   543     void subat( uint );
       
   544     bool findArg(int& pos, int& len) const;
       
   545 
       
   546     static QChar* asciiToUnicode( const char*, uint * len, uint maxlen=(uint)-1 );
       
   547     static QChar* asciiToUnicode( const QByteArray&, uint * len );
       
   548     static char* unicodeToAscii( const QChar*, uint len );
       
   549 
       
   550     QStringData *d;
       
   551     static QStringData* shared_null;
       
   552     static QStringData* makeSharedNull();
       
   553 
       
   554     friend class QConstString;
       
   555     QString(QStringData* dd, bool /*dummy*/) : d(dd) { }
       
   556 };
       
   557 
       
   558 class Q_EXPORT QCharRef {
       
   559     friend class QString;
       
   560     QString& s;
       
   561     uint p;
       
   562     QCharRef(QString* str, uint pos) : s(*str), p(pos) { }
       
   563 
       
   564 public:
       
   565     // Most QChar operations repeated here...
       
   566 
       
   567     // all this is not documented: We just say "like QChar" and let it be.
       
   568 #if 1
       
   569     ushort unicode() const { return s.constref(p).unicode(); }
       
   570     char latin1() const { return s.constref(p).latin1(); }
       
   571 
       
   572     // An operator= for each QChar cast constructor...
       
   573     QCharRef operator=(char c ) { s.ref(p)=c; return *this; }
       
   574     QCharRef operator=(uchar c ) { s.ref(p)=c; return *this; }
       
   575     QCharRef operator=(QChar c ) { s.ref(p)=c; return *this; }
       
   576     QCharRef operator=(const QCharRef& c ) { s.ref(p)=c.unicode(); return *this; }
       
   577     QCharRef operator=(ushort rc ) { s.ref(p)=rc; return *this; }
       
   578     QCharRef operator=(short rc ) { s.ref(p)=rc; return *this; }
       
   579     QCharRef operator=(uint rc ) { s.ref(p)=rc; return *this; }
       
   580     QCharRef operator=(int rc ) { s.ref(p)=rc; return *this; }
       
   581 
       
   582     operator QChar () const { return s.constref(p); }
       
   583 
       
   584     // each function...
       
   585     bool isNull() const { return unicode()==0; }
       
   586     bool isPrint() const { return s.constref(p).isPrint(); }
       
   587     bool isPunct() const { return s.constref(p).isPunct(); }
       
   588     bool isSpace() const { return s.constref(p).isSpace(); }
       
   589     bool isMark() const { return s.constref(p).isMark(); }
       
   590     bool isLetter() const { return s.constref(p).isLetter(); }
       
   591     bool isNumber() const { return s.constref(p).isNumber(); }
       
   592     bool isLetterOrNumber() { return s.constref(p).isLetterOrNumber(); }
       
   593     bool isDigit() const { return s.constref(p).isDigit(); }
       
   594 
       
   595     int digitValue() const { return s.constref(p).digitValue(); }
       
   596     QChar lower() { return s.constref(p).lower(); }
       
   597     QChar upper() { return s.constref(p).upper(); }
       
   598 
       
   599     QChar::Category category() const { return s.constref(p).category(); }
       
   600     QChar::Direction direction() const { return s.constref(p).direction(); }
       
   601     QChar::Joining joining() const { return s.constref(p).joining(); }
       
   602     bool mirrored() const { return s.constref(p).mirrored(); }
       
   603     QChar mirroredChar() const { return s.constref(p).mirroredChar(); }
       
   604     QString decomposition() const { return s.constref(p).decomposition(); }
       
   605     QChar::Decomposition decompositionTag() const { return s.constref(p).decompositionTag(); }
       
   606 
       
   607     // Not the non-const ones of these.
       
   608     uchar cell() const { return s.constref(p).cell(); }
       
   609     uchar row() const { return s.constref(p).row(); }
       
   610 #endif
       
   611 };
       
   612 
       
   613 inline QCharRef QString::at( uint i ) { return QCharRef(this,i); }
       
   614 inline QCharRef QString::operator[]( int i ) { return at((uint)i); }
       
   615 
       
   616 
       
   617 class Q_EXPORT QConstString : private QString {
       
   618 public:
       
   619     QConstString( QChar* unicode, uint length );
       
   620     ~QConstString();
       
   621     const QString& string() const { return *this; }
       
   622 };
       
   623 
       
   624 
       
   625 /*****************************************************************************
       
   626   QString stream functions
       
   627  *****************************************************************************/
       
   628 #ifndef QT_NO_DATASTREAM
       
   629 Q_EXPORT QDataStream &operator<<( QDataStream &, const QString & );
       
   630 Q_EXPORT QDataStream &operator>>( QDataStream &, QString & );
       
   631 #endif
       
   632 
       
   633 /*****************************************************************************
       
   634   QString inline functions
       
   635  *****************************************************************************/
       
   636 
       
   637 // These two move code into makeSharedNull() and deletesData()
       
   638 // to improve cache-coherence (and reduce code bloat), while
       
   639 // keeping the common cases fast.
       
   640 //
       
   641 // No safe way to pre-init shared_null on ALL compilers/linkers.
       
   642 inline QString::QString() :
       
   643     d(shared_null ? shared_null : makeSharedNull())
       
   644 {
       
   645     d->ref();
       
   646 }
       
   647 //
       
   648 inline QString::~QString()
       
   649 {
       
   650     if ( d->deref() ) {
       
   651 	if ( d == shared_null )
       
   652 	    shared_null = 0;
       
   653 	d->deleteSelf();
       
   654     }
       
   655 }
       
   656 
       
   657 inline QString &QString::operator=( QChar c )
       
   658 { return *this = QString(c); }
       
   659 
       
   660 inline QString &QString::operator=( char c )
       
   661 { return *this = QString(QChar(c)); }
       
   662 
       
   663 inline bool QString::isNull() const
       
   664 { return unicode() == 0; }
       
   665 
       
   666 inline bool QString::operator!() const
       
   667 { return isNull(); }
       
   668 
       
   669 inline uint QString::length() const
       
   670 { return d->len; }
       
   671 
       
   672 inline bool QString::isEmpty() const
       
   673 { return length() == 0; }
       
   674 
       
   675 inline QString QString::copy() const
       
   676 { return QString( *this ); }
       
   677 
       
   678 inline QString &QString::prepend( const QString & s )
       
   679 { return insert(0,s); }
       
   680 
       
   681 inline QString &QString::prepend( QChar c )
       
   682 { return insert(0,c); }
       
   683 
       
   684 inline QString &QString::prepend( char c )
       
   685 { return insert(0,c); }
       
   686 
       
   687 inline QString &QString::append( const QString & s )
       
   688 { return operator+=(s); }
       
   689 
       
   690 inline QString &QString::append( QChar c )
       
   691 { return operator+=(c); }
       
   692 
       
   693 inline QString &QString::append( char c )
       
   694 { return operator+=(c); }
       
   695 
       
   696 inline QString &QString::setNum( short n, int base )
       
   697 { return setNum((long)n, base); }
       
   698 
       
   699 inline QString &QString::setNum( ushort n, int base )
       
   700 { return setNum((ulong)n, base); }
       
   701 
       
   702 inline QString &QString::setNum( int n, int base )
       
   703 { return setNum((long)n, base); }
       
   704 
       
   705 inline QString &QString::setNum( uint n, int base )
       
   706 { return setNum((ulong)n, base); }
       
   707 
       
   708 inline QString &QString::setNum( float n, char f, int prec )
       
   709 { return setNum((double)n,f,prec); }
       
   710 
       
   711 inline QString QString::arg(int a, int fieldwidth, int base) const
       
   712 { return arg((long)a, fieldwidth, base); }
       
   713 
       
   714 inline QString QString::arg(uint a, int fieldwidth, int base) const
       
   715 { return arg((ulong)a, fieldwidth, base); }
       
   716 
       
   717 inline QString QString::arg(short a, int fieldwidth, int base) const
       
   718 { return arg((long)a, fieldwidth, base); }
       
   719 
       
   720 inline QString QString::arg(ushort a, int fieldwidth, int base) const
       
   721 { return arg((ulong)a, fieldwidth, base); }
       
   722 
       
   723 inline int QString::find( char c, int index, bool cs ) const
       
   724 { return find(QChar(c), index, cs); }
       
   725 
       
   726 inline int QString::findRev( char c, int index, bool cs) const
       
   727 { return findRev( QChar(c), index, cs ); }
       
   728 
       
   729 
       
   730 #ifndef QT_NO_CAST_ASCII
       
   731 inline int QString::find( const char* str, int index ) const
       
   732 { return find(QString::fromLatin1(str), index); }
       
   733 
       
   734 inline int QString::findRev( const char* str, int index ) const
       
   735 { return findRev(QString::fromLatin1(str), index); }
       
   736 #endif
       
   737 
       
   738 
       
   739 /*****************************************************************************
       
   740   QString non-member operators
       
   741  *****************************************************************************/
       
   742 
       
   743 Q_EXPORT bool operator!=( const QString &s1, const QString &s2 );
       
   744 Q_EXPORT bool operator<( const QString &s1, const QString &s2 );
       
   745 Q_EXPORT bool operator<=( const QString &s1, const QString &s2 );
       
   746 Q_EXPORT bool operator==( const QString &s1, const QString &s2 );
       
   747 Q_EXPORT bool operator>( const QString &s1, const QString &s2 );
       
   748 Q_EXPORT bool operator>=( const QString &s1, const QString &s2 );
       
   749 #ifndef QT_NO_CAST_ASCII
       
   750 Q_EXPORT bool operator!=( const QString &s1, const char *s2 );
       
   751 Q_EXPORT bool operator<( const QString &s1, const char *s2 );
       
   752 Q_EXPORT bool operator<=( const QString &s1, const char *s2 );
       
   753 Q_EXPORT bool operator==( const QString &s1, const char *s2 );
       
   754 Q_EXPORT bool operator>( const QString &s1, const char *s2 );
       
   755 Q_EXPORT bool operator>=( const QString &s1, const char *s2 );
       
   756 Q_EXPORT bool operator!=( const char *s1, const QString &s2 );
       
   757 Q_EXPORT bool operator<( const char *s1, const QString &s2 );
       
   758 Q_EXPORT bool operator<=( const char *s1, const QString &s2 );
       
   759 Q_EXPORT bool operator==( const char *s1, const QString &s2 );
       
   760 //Q_EXPORT bool operator>( const char *s1, const QString &s2 ); // MSVC++
       
   761 Q_EXPORT bool operator>=( const char *s1, const QString &s2 );
       
   762 #endif
       
   763 
       
   764 Q_EXPORT inline QString operator+( const QString &s1, const QString &s2 )
       
   765 {
       
   766     QString tmp( s1 );
       
   767     tmp += s2;
       
   768     return tmp;
       
   769 }
       
   770 
       
   771 #ifndef QT_NO_CAST_ASCII
       
   772 Q_EXPORT inline QString operator+( const QString &s1, const char *s2 )
       
   773 {
       
   774     QString tmp( s1 );
       
   775     tmp += QString::fromLatin1(s2);
       
   776     return tmp;
       
   777 }
       
   778 
       
   779 Q_EXPORT inline QString operator+( const char *s1, const QString &s2 )
       
   780 {
       
   781     QString tmp = QString::fromLatin1( s1 );
       
   782     tmp += s2;
       
   783     return tmp;
       
   784 }
       
   785 #endif
       
   786 
       
   787 Q_EXPORT inline QString operator+( const QString &s1, QChar c2 )
       
   788 {
       
   789     QString tmp( s1 );
       
   790     tmp += c2;
       
   791     return tmp;
       
   792 }
       
   793 
       
   794 Q_EXPORT inline QString operator+( const QString &s1, char c2 )
       
   795 {
       
   796     QString tmp( s1 );
       
   797     tmp += c2;
       
   798     return tmp;
       
   799 }
       
   800 
       
   801 Q_EXPORT inline QString operator+( QChar c1, const QString &s2 )
       
   802 {
       
   803     QString tmp;
       
   804     tmp += c1;
       
   805     tmp += s2;
       
   806     return tmp;
       
   807 }
       
   808 
       
   809 Q_EXPORT inline QString operator+( char c1, const QString &s2 )
       
   810 {
       
   811     QString tmp;
       
   812     tmp += c1;
       
   813     tmp += s2;
       
   814     return tmp;
       
   815 }
       
   816 
       
   817 #if defined(_OS_WIN32_)
       
   818 extern Q_EXPORT QString qt_winQString(void*);
       
   819 extern Q_EXPORT const void* qt_winTchar(const QString& str, bool addnul);
       
   820 extern Q_EXPORT void* qt_winTchar_new(const QString& str);
       
   821 extern Q_EXPORT QCString qt_winQString2MB( const QString& s, int len=-1 );
       
   822 extern Q_EXPORT QString qt_winMB2QString( const char* mb, int len=-1 );
       
   823 #endif
       
   824 
       
   825 #endif // QSTRING_H