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