summaryrefslogtreecommitdiff
path: root/qmake/include/qstring.h
Unidiff
Diffstat (limited to 'qmake/include/qstring.h') (more/less context) (show whitespace changes)
-rw-r--r--qmake/include/qstring.h91
1 files changed, 66 insertions, 25 deletions
diff --git a/qmake/include/qstring.h b/qmake/include/qstring.h
index 2a87a5a..c1d6740 100644
--- a/qmake/include/qstring.h
+++ b/qmake/include/qstring.h
@@ -1,69 +1,75 @@
1/**************************************************************************** 1/****************************************************************************
2** $Id$ 2** $Id$
3** 3**
4** Definition of the QString class, and related Unicode 4** Definition of the QString class, and related Unicode functions.
5** functions.
6** 5**
7** Created : 920609 6** Created : 920609
8** 7**
9** Copyright (C) 1992-2000 Trolltech AS. All rights reserved. 8** Copyright (C) 1992-2002 Trolltech AS. All rights reserved.
10** 9**
11** This file is part of the tools module of the Qt GUI Toolkit. 10** This file is part of the tools module of the Qt GUI Toolkit.
12** 11**
13** This file may be distributed under the terms of the Q Public License 12** 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 13** as defined by Trolltech AS of Norway and appearing in the file
15** LICENSE.QPL included in the packaging of this file. 14** LICENSE.QPL included in the packaging of this file.
16** 15**
17** This file may be distributed and/or modified under the terms of the 16** 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 17** GNU General Public License version 2 as published by the Free Software
19** Foundation and appearing in the file LICENSE.GPL included in the 18** Foundation and appearing in the file LICENSE.GPL included in the
20** packaging of this file. 19** packaging of this file.
21** 20**
22** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition 21** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
23** licenses may use this file in accordance with the Qt Commercial License 22** licenses may use this file in accordance with the Qt Commercial License
24** Agreement provided with the Software. 23** Agreement provided with the Software.
25** 24**
26** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 25** 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. 26** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
28** 27**
29** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for 28** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
30** information about Qt Commercial License Agreements. 29** information about Qt Commercial License Agreements.
31** See http://www.trolltech.com/qpl/ for QPL licensing information. 30** See http://www.trolltech.com/qpl/ for QPL licensing information.
32** See http://www.trolltech.com/gpl/ for GPL licensing information. 31** See http://www.trolltech.com/gpl/ for GPL licensing information.
33** 32**
34** Contact info@trolltech.com if any conditions of this licensing are 33** Contact info@trolltech.com if any conditions of this licensing are
35** not clear to you. 34** not clear to you.
36** 35**
37**********************************************************************/ 36**********************************************************************/
38 37
39#ifndef QSTRING_H 38#ifndef QSTRING_H
40#define QSTRING_H 39#define QSTRING_H
41 40
42#ifndef QT_H 41#ifndef QT_H
43#include "qcstring.h" 42#include "qcstring.h"
44#endif // QT_H 43#endif // QT_H
45 44
45#ifndef QT_NO_STL
46#include <string>
47#if defined(Q_WRONG_SB_CTYPE_MACROS) && defined(_SB_CTYPE_MACROS)
48#undef _SB_CTYPE_MACROS
49#endif
50#endif
51
46 52
47/***************************************************************************** 53/*****************************************************************************
48 QString class 54 QString class
49 *****************************************************************************/ 55 *****************************************************************************/
50 56
51class QRegExp; 57class QRegExp;
52class QString; 58class QString;
53class QCharRef; 59class QCharRef;
54template <class T> class QDeepCopy; 60template <class T> class QDeepCopy;
55 61
56class Q_EXPORT QChar { 62class Q_EXPORT QChar {
57public: 63public:
58 QChar(); 64 QChar();
59 QChar( char c ); 65 QChar( char c );
60 QChar( uchar c ); 66 QChar( uchar c );
61 QChar( uchar c, uchar r ); 67 QChar( uchar c, uchar r );
62 QChar( const QChar& c ); 68 QChar( const QChar& c );
63 QChar( ushort rc ); 69 QChar( ushort rc );
64 QChar( short rc ); 70 QChar( short rc );
65 QChar( uint rc ); 71 QChar( uint rc );
66 QChar( int rc ); 72 QChar( int rc );
67 73
68 QT_STATIC_CONST QChar null; // 0000 74 QT_STATIC_CONST QChar null; // 0000
69 QT_STATIC_CONST QChar replacement; // FFFD 75 QT_STATIC_CONST QChar replacement; // FFFD
@@ -315,101 +321,105 @@ inline bool operator<=( QChar c, char ch )
315 321
316inline bool operator<=( char ch, QChar c ) 322inline bool operator<=( char ch, QChar c )
317{ 323{
318 return ((uchar) ch) <= c.ucs; 324 return ((uchar) ch) <= c.ucs;
319} 325}
320 326
321inline bool operator<=( QChar c1, QChar c2 ) 327inline bool operator<=( QChar c1, QChar c2 )
322{ 328{
323 return c1.ucs <= c2.ucs; 329 return c1.ucs <= c2.ucs;
324} 330}
325 331
326inline bool operator>=( QChar c, char ch ) { return ch <= c; } 332inline bool operator>=( QChar c, char ch ) { return ch <= c; }
327inline bool operator>=( char ch, QChar c ) { return c <= ch; } 333inline bool operator>=( char ch, QChar c ) { return c <= ch; }
328inline bool operator>=( QChar c1, QChar c2 ) { return c2 <= c1; } 334inline bool operator>=( QChar c1, QChar c2 ) { return c2 <= c1; }
329inline bool operator<( QChar c, char ch ) { return !(ch<=c); } 335inline bool operator<( QChar c, char ch ) { return !(ch<=c); }
330inline bool operator<( char ch, QChar c ) { return !(c<=ch); } 336inline bool operator<( char ch, QChar c ) { return !(c<=ch); }
331inline bool operator<( QChar c1, QChar c2 ) { return !(c2<=c1); } 337inline bool operator<( QChar c1, QChar c2 ) { return !(c2<=c1); }
332inline bool operator>( QChar c, char ch ) { return !(ch>=c); } 338inline bool operator>( QChar c, char ch ) { return !(ch>=c); }
333inline bool operator>( char ch, QChar c ) { return !(c>=ch); } 339inline bool operator>( char ch, QChar c ) { return !(c>=ch); }
334inline bool operator>( QChar c1, QChar c2 ) { return !(c2>=c1); } 340inline bool operator>( QChar c1, QChar c2 ) { return !(c2>=c1); }
335 341
336// internal 342// internal
337struct Q_EXPORT QStringData : public QShared { 343struct Q_EXPORT QStringData : public QShared {
338 QStringData() : 344 QStringData() :
339 QShared(), unicode(0), ascii(0), len(0), simpletext(1), maxl(0), dirty(0) { ref(); } 345 QShared(), unicode(0), ascii(0), len(0), issimpletext(TRUE), maxl(0), islatin1(FALSE) { ref(); }
340 QStringData(QChar *u, uint l, uint m) : 346 QStringData(QChar *u, uint l, uint m) :
341 QShared(), unicode(u), ascii(0), len(l), simpletext(1), maxl(m), dirty(1) { } 347 QShared(), unicode(u), ascii(0), len(l), issimpletext(FALSE), maxl(m), islatin1(FALSE) { }
342 ~QStringData() { if ( unicode ) delete[] ((char*)unicode); 348 ~QStringData() { if ( unicode ) delete[] ((char*)unicode);
343 if ( ascii ) delete[] ascii; } 349 if ( ascii ) delete[] ascii; }
344 350
345 void deleteSelf(); 351 void deleteSelf();
346 QChar *unicode; 352 QChar *unicode;
347 char *ascii; 353 char *ascii;
348 void setDirty() { 354 void setDirty() {
349 if ( ascii ) { 355 if ( ascii ) {
350 delete [] ascii; 356 delete [] ascii;
351 ascii = 0; 357 ascii = 0;
352 } 358 }
353 dirty = 1; 359 issimpletext = FALSE;
354 } 360 }
355#ifdef Q_OS_MAC9 361#ifdef Q_OS_MAC9
356 uint len; 362 uint len;
357#else 363#else
358 uint len : 30; 364 uint len : 30;
359#endif 365#endif
360 uint simpletext : 1; 366 uint issimpletext : 1;
361#ifdef Q_OS_MAC9 367#ifdef Q_OS_MAC9
362 uint maxl; 368 uint maxl;
363#else 369#else
364 uint maxl : 30; 370 uint maxl : 30;
365#endif 371#endif
366 uint dirty : 1; 372 uint islatin1 : 1;
367 373
368private: 374private:
369#if defined(Q_DISABLE_COPY) 375#if defined(Q_DISABLE_COPY)
370 QStringData( const QStringData& ); 376 QStringData( const QStringData& );
371 QStringData& operator=( const QStringData& ); 377 QStringData& operator=( const QStringData& );
372#endif 378#endif
373}; 379};
374 380
375 381
376class Q_EXPORT QString 382class Q_EXPORT QString
377{ 383{
378public: 384public:
379 QString(); // make null string 385 QString(); // make null string
380 QString( QChar ); // one-char string 386 QString( QChar ); // one-char string
381 QString( const QString & ); // impl-shared copy 387 QString( const QString & ); // impl-shared copy
382 QString( const QByteArray& ); // deep copy 388 QString( const QByteArray& ); // deep copy
383 QString( const QChar* unicode, uint length ); // deep copy 389 QString( const QChar* unicode, uint length ); // deep copy
384#ifndef QT_NO_CAST_ASCII 390#ifndef QT_NO_CAST_ASCII
385 QString( const char *str ); // deep copy 391 QString( const char *str ); // deep copy
386#endif 392#endif
393#ifndef QT_NO_STL
394 QString( const std::string& ); // deep copy
395#endif
387 ~QString(); 396 ~QString();
388 397
389 QString &operator=( const QString & ); // impl-shared copy 398 QString &operator=( const QString & ); // impl-shared copy
390#ifndef QT_NO_CAST_ASCII
391 QString &operator=( const char * ); // deep copy 399 QString &operator=( const char * ); // deep copy
400#ifndef QT_NO_STL
401 QString &operator=( const std::string& ); // deep copy
392#endif 402#endif
393 QString &operator=( const QCString& ); // deep copy 403 QString &operator=( const QCString& ); // deep copy
394 QString &operator=( QChar c ); 404 QString &operator=( QChar c );
395 QString &operator=( char c ); 405 QString &operator=( char c );
396 406
397 QT_STATIC_CONST QString null; 407 QT_STATIC_CONST QString null;
398 408
399 bool isNull() const; 409 bool isNull() const;
400 bool isEmpty() const; 410 bool isEmpty() const;
401 uint length() const; 411 uint length() const;
402 void truncate( uint pos ); 412 void truncate( uint pos );
403 413
404 QString & fill( QChar c, int len = -1 ); 414 QString & fill( QChar c, int len = -1 );
405 415
406 QString copy() const; 416 QString copy() const;
407 417
408 QString arg( long a, int fieldwidth=0, int base=10 ) const; 418 QString arg( long a, int fieldwidth=0, int base=10 ) const;
409 QString arg( ulong a, int fieldwidth=0, int base=10 ) const; 419 QString arg( ulong a, int fieldwidth=0, int base=10 ) const;
410 QString arg( int a, int fieldwidth=0, int base=10 ) const; 420 QString arg( int a, int fieldwidth=0, int base=10 ) const;
411 QString arg( uint a, int fieldwidth=0, int base=10 ) const; 421 QString arg( uint a, int fieldwidth=0, int base=10 ) const;
412 QString arg( short a, int fieldwidth=0, int base=10 ) const; 422 QString arg( short a, int fieldwidth=0, int base=10 ) const;
413 QString arg( ushort a, int fieldwidth=0, int base=10 ) const; 423 QString arg( ushort a, int fieldwidth=0, int base=10 ) const;
414 QString arg( char a, int fieldwidth=0 ) const; 424 QString arg( char a, int fieldwidth=0 ) const;
415 QString arg( QChar a, int fieldwidth=0 ) const; 425 QString arg( QChar a, int fieldwidth=0 ) const;
@@ -473,55 +483,61 @@ public:
473 QString left( uint len ) const; 483 QString left( uint len ) const;
474 QString right( uint len ) const; 484 QString right( uint len ) const;
475 QString mid( uint index, uint len=0xffffffff) const; 485 QString mid( uint index, uint len=0xffffffff) const;
476 486
477 QString leftJustify( uint width, QChar fill=' ', bool trunc=FALSE)const; 487 QString leftJustify( uint width, QChar fill=' ', bool trunc=FALSE)const;
478 QString rightJustify( uint width, QChar fill=' ',bool trunc=FALSE)const; 488 QString rightJustify( uint width, QChar fill=' ',bool trunc=FALSE)const;
479 489
480 QString lower() const; 490 QString lower() const;
481 QString upper() const; 491 QString upper() const;
482 492
483 QString stripWhiteSpace() const; 493 QString stripWhiteSpace() const;
484 QString simplifyWhiteSpace() const; 494 QString simplifyWhiteSpace() const;
485 495
486 QString &insert( uint index, const QString & ); 496 QString &insert( uint index, const QString & );
487 QString &insert( uint index, const QChar*, uint len ); 497 QString &insert( uint index, const QChar*, uint len );
488 QString &insert( uint index, QChar ); 498 QString &insert( uint index, QChar );
489 QString &insert( uint index, char c ) { return insert(index,QChar(c)); } 499 QString &insert( uint index, char c ) { return insert(index,QChar(c)); }
490 QString &append( char ); 500 QString &append( char );
491 QString &append( QChar ); 501 QString &append( QChar );
492 QString &append( const QString & ); 502 QString &append( const QString & );
493#ifndef QT_NO_CAST_ASCII 503#ifndef QT_NO_CAST_ASCII
494 QString &append( const QByteArray & ); 504 QString &append( const QByteArray & );
495 QString &append( const char * ); 505 QString &append( const char * );
496#endif 506#endif
507#ifndef QT_NO_STL
508 QString &append( const std::string& );
509#endif
497 QString &prepend( char ); 510 QString &prepend( char );
498 QString &prepend( QChar ); 511 QString &prepend( QChar );
499 QString &prepend( const QString & ); 512 QString &prepend( const QString & );
500#ifndef QT_NO_CAST_ASCII 513#ifndef QT_NO_CAST_ASCII
501 QString &prepend( const QByteArray & ); 514 QString &prepend( const QByteArray & );
502 QString &prepend( const char * ); 515 QString &prepend( const char * );
503#endif 516#endif
517#ifndef QT_NO_STL
518 QString &prepend( const std::string& );
519#endif
504 QString &remove( uint index, uint len ); 520 QString &remove( uint index, uint len );
505 QString &remove( QChar c ); 521 QString &remove( QChar c );
506 QString &remove( char c ) { return remove( QChar(c) ); } 522 QString &remove( char c ) { return remove( QChar(c) ); }
507 QString &remove( const QString & ); 523 QString &remove( const QString & );
508#ifndef QT_NO_REGEXP 524#ifndef QT_NO_REGEXP
509 QString &remove( const QRegExp & ); 525 QString &remove( const QRegExp & );
510#endif 526#endif
511#ifndef QT_NO_CAST_ASCII 527#ifndef QT_NO_CAST_ASCII
512 QString &remove( const char * ); 528 QString &remove( const char * );
513#endif 529#endif
514 QString &replace( uint index, uint len, const QString & ); 530 QString &replace( uint index, uint len, const QString & );
515 QString &replace( uint index, uint len, const QChar*, uint clen ); 531 QString &replace( uint index, uint len, const QChar*, uint clen );
516 QString &replace( uint index, uint len, QChar ); 532 QString &replace( uint index, uint len, QChar );
517 QString &replace( uint index, uint len, char c ) 533 QString &replace( uint index, uint len, char c )
518 { return replace( index, len, QChar(c) ); } 534 { return replace( index, len, QChar(c) ); }
519 QString &replace( QChar c, const QString & ); 535 QString &replace( QChar c, const QString & );
520 QString &replace( char c, const QString & after ) 536 QString &replace( char c, const QString & after )
521 { return replace( QChar(c), after ); } 537 { return replace( QChar(c), after ); }
522 QString &replace( const QString &, const QString & ); 538 QString &replace( const QString &, const QString & );
523#ifndef QT_NO_REGEXP_CAPTURE 539#ifndef QT_NO_REGEXP_CAPTURE
524 QString &replace( const QRegExp &, const QString & ); 540 QString &replace( const QRegExp &, const QString & );
525#endif 541#endif
526 QString &replace( QChar, QChar ); 542 QString &replace( QChar, QChar );
527 543
@@ -535,126 +551,135 @@ public:
535 double toDouble( bool *ok=0 ) const; 551 double toDouble( bool *ok=0 ) const;
536 552
537 QString &setNum( short, int base=10 ); 553 QString &setNum( short, int base=10 );
538 QString &setNum( ushort, int base=10 ); 554 QString &setNum( ushort, int base=10 );
539 QString &setNum( int, int base=10 ); 555 QString &setNum( int, int base=10 );
540 QString &setNum( uint, int base=10 ); 556 QString &setNum( uint, int base=10 );
541 QString &setNum( long, int base=10 ); 557 QString &setNum( long, int base=10 );
542 QString &setNum( ulong, int base=10 ); 558 QString &setNum( ulong, int base=10 );
543 QString &setNum( float, char f='g', int prec=6 ); 559 QString &setNum( float, char f='g', int prec=6 );
544 QString &setNum( double, char f='g', int prec=6 ); 560 QString &setNum( double, char f='g', int prec=6 );
545 561
546 static QString number( long, int base=10 ); 562 static QString number( long, int base=10 );
547 static QString number( ulong, int base=10); 563 static QString number( ulong, int base=10);
548 static QString number( int, int base=10 ); 564 static QString number( int, int base=10 );
549 static QString number( uint, int base=10); 565 static QString number( uint, int base=10);
550 static QString number( double, char f='g', int prec=6 ); 566 static QString number( double, char f='g', int prec=6 );
551 567
552 void setExpand( uint index, QChar c ); 568 void setExpand( uint index, QChar c );
553 569
554 QString &operator+=( const QString &str ); 570 QString &operator+=( const QString &str );
555#ifndef QT_NO_CAST_ASCII 571#ifndef QT_NO_CAST_ASCII
556 QString &operator+=( const QByteArray &str ); 572 QString &operator+=( const QByteArray &str );
557 QString &operator+=( const char *str ); 573 QString &operator+=( const char *str );
558#endif 574#endif
575#ifndef QT_NO_STL
576 QString &operator+=( const std::string& );
577#endif
559 QString &operator+=( QChar c ); 578 QString &operator+=( QChar c );
560 QString &operator+=( char c ); 579 QString &operator+=( char c );
561 580
562 QChar at( uint i ) const 581 QChar at( uint i ) const
563 { return i < d->len ? d->unicode[i] : QChar::null; } 582 { return i < d->len ? d->unicode[i] : QChar::null; }
564 QChar operator[]( int i ) const { return at((uint)i); } 583 QChar operator[]( int i ) const { return at((uint)i); }
565 QCharRef at( uint i ); 584 QCharRef at( uint i );
566 QCharRef operator[]( int i ); 585 QCharRef operator[]( int i );
567 586
568 QChar constref(uint i) const 587 QChar constref(uint i) const
569 { return at(i); } 588 { return at(i); }
570 QChar& ref(uint i) 589 QChar& ref(uint i)
571 { // Optimized for easy-inlining by simple compilers. 590 { // Optimized for easy-inlining by simple compilers.
572 if ( d->count != 1 || i >= d->len ) 591 if ( d->count != 1 || i >= d->len )
573 subat( i ); 592 subat( i );
574 d->setDirty(); 593 d->setDirty();
575 return d->unicode[i]; 594 return d->unicode[i];
576 } 595 }
577 596
578 const QChar* unicode() const { return d->unicode; } 597 const QChar* unicode() const { return d->unicode; }
579 const char* ascii() const { return latin1(); } 598 const char* ascii() const;
599 static QString fromAscii(const char*, int len=-1);
580 const char* latin1() const; 600 const char* latin1() const;
581 static QString fromLatin1(const char*, int len=-1); 601 static QString fromLatin1(const char*, int len=-1);
582 QCString utf8() const; 602 QCString utf8() const;
583 static QString fromUtf8(const char*, int len=-1); 603 static QString fromUtf8(const char*, int len=-1);
584 QCString local8Bit() const; 604 QCString local8Bit() const;
585 static QString fromLocal8Bit(const char*, int len=-1); 605 static QString fromLocal8Bit(const char*, int len=-1);
586 bool operator!() const; 606 bool operator!() const;
587#ifndef QT_NO_ASCII_CAST 607#ifndef QT_NO_ASCII_CAST
588 operator const char *() const { return latin1(); } 608 operator const char *() const { return ascii(); }
609#endif
610#ifndef QT_NO_STL
611 operator std::string() const { return ascii() ? ascii() : ""; }
589#endif 612#endif
613
590 static QString fromUcs2( const unsigned short *ucs2 ); 614 static QString fromUcs2( const unsigned short *ucs2 );
591 const unsigned short *ucs2() const; 615 const unsigned short *ucs2() const;
592 616
593 QString &setUnicode( const QChar* unicode, uint len ); 617 QString &setUnicode( const QChar* unicode, uint len );
594 QString &setUnicodeCodes( const ushort* unicode_as_ushorts, uint len ); 618 QString &setUnicodeCodes( const ushort* unicode_as_ushorts, uint len );
619 QString &setAscii( const char*, int len=-1 );
595 QString &setLatin1( const char*, int len=-1 ); 620 QString &setLatin1( const char*, int len=-1 );
596 621
597 int compare( const QString& s ) const; 622 int compare( const QString& s ) const;
598 static int compare( const QString& s1, const QString& s2 ) 623 static int compare( const QString& s1, const QString& s2 )
599 { return s1.compare( s2 ); } 624 { return s1.compare( s2 ); }
600 625
601 int localeAwareCompare( const QString& s ) const; 626 int localeAwareCompare( const QString& s ) const;
602 static int localeAwareCompare( const QString& s1, const QString& s2 ) 627 static int localeAwareCompare( const QString& s1, const QString& s2 )
603 { return s1.localeAwareCompare( s2 ); } 628 { return s1.localeAwareCompare( s2 ); }
604 629
605#ifndef QT_NO_DATASTREAM 630#ifndef QT_NO_DATASTREAM
606 friend Q_EXPORT QDataStream &operator>>( QDataStream &, QString & ); 631 friend Q_EXPORT QDataStream &operator>>( QDataStream &, QString & );
607#endif 632#endif
608 633
609 void compose(); 634 void compose();
610 635
611#ifndef QT_NO_COMPAT 636#ifndef QT_NO_COMPAT
612 const char* data() const { return latin1(); } 637 const char* data() const { return ascii(); }
613#endif 638#endif
614 639
615 bool startsWith( const QString& ) const; 640 bool startsWith( const QString& ) const;
616 bool endsWith( const QString& ) const; 641 bool endsWith( const QString& ) const;
617 642
618 void setLength( uint newLength ); 643 void setLength( uint newLength );
619 644
620 bool simpleText() const { if ( d->dirty ) checkSimpleText(); return (bool)d->simpletext; } 645 bool simpleText() const { if ( !d->issimpletext ) checkSimpleText(); return (bool)d->issimpletext; }
621 bool isRightToLeft() const; 646 bool isRightToLeft() const;
622 647
623 648
624private: 649private:
625 QString( int size, bool /* dummy */ );// allocate size incl. \0 650 QString( int size, bool /* dummy */ );// allocate size incl. \0
626 651
627 void deref(); 652 void deref();
628 void real_detach(); 653 void real_detach();
629 void subat( uint ); 654 void subat( uint );
630 bool findArg(int& pos, int& len) const; 655 bool findArg(int& pos, int& len) const;
631 656
632 void checkSimpleText() const; 657 void checkSimpleText() const;
633 658
634 static QChar* asciiToUnicode( const char*, uint * len, uint maxlen=(uint)-1 ); 659 static QChar* latin1ToUnicode( const char*, uint * len, uint maxlen=(uint)-1 );
635 static QChar* asciiToUnicode( const QByteArray&, uint * len ); 660 static QChar* latin1ToUnicode( const QByteArray&, uint * len );
636 static char* unicodeToAscii( const QChar*, uint len ); 661 static char* unicodeToLatin1( const QChar*, uint len );
637 662
638 QStringData *d; 663 QStringData *d;
639 static QStringData* shared_null; 664 static QStringData* shared_null;
640 static QStringData* makeSharedNull(); 665 static QStringData* makeSharedNull();
641 666
642 friend class QConstString; 667 friend class QConstString;
643 friend class QTextStream; 668 friend class QTextStream;
644 QString( QStringData* dd, bool /* dummy */ ) : d(dd) { } 669 QString( QStringData* dd, bool /* dummy */ ) : d(dd) { }
645 670
646 // needed for QDeepCopy 671 // needed for QDeepCopy
647 void detach(); 672 void detach();
648 friend class QDeepCopy<QString>; 673 friend class QDeepCopy<QString>;
649}; 674};
650 675
651class Q_EXPORT QCharRef { 676class Q_EXPORT QCharRef {
652 friend class QString; 677 friend class QString;
653 QString& s; 678 QString& s;
654 uint p; 679 uint p;
655 QCharRef(QString* str, uint pos) : s(*str), p(pos) { } 680 QCharRef(QString* str, uint pos) : s(*str), p(pos) { }
656 681
657public: 682public:
658 // most QChar operations repeated here... 683 // most QChar operations repeated here...
659 684
660 // all this is not documented: We just say "like QChar" and let it be. 685 // all this is not documented: We just say "like QChar" and let it be.
@@ -773,178 +798,194 @@ inline bool QString::isNull() const
773 798
774inline bool QString::operator!() const 799inline bool QString::operator!() const
775{ return isNull(); } 800{ return isNull(); }
776 801
777inline uint QString::length() const 802inline uint QString::length() const
778{ return d->len; } 803{ return d->len; }
779 804
780inline bool QString::isEmpty() const 805inline bool QString::isEmpty() const
781{ return length() == 0; } 806{ return length() == 0; }
782 807
783inline QString QString::copy() const 808inline QString QString::copy() const
784{ return QString( *this ); } 809{ return QString( *this ); }
785 810
786inline QString &QString::prepend( const QString & s ) 811inline QString &QString::prepend( const QString & s )
787{ return insert(0,s); } 812{ return insert(0,s); }
788 813
789inline QString &QString::prepend( QChar c ) 814inline QString &QString::prepend( QChar c )
790{ return insert(0,c); } 815{ return insert(0,c); }
791 816
792inline QString &QString::prepend( char c ) 817inline QString &QString::prepend( char c )
793{ return insert(0,c); } 818{ return insert(0,c); }
794 819
795#ifndef QT_NO_CAST_ASCII 820#ifndef QT_NO_CAST_ASCII
796inline QString &QString::prepend( const QByteArray & s ) 821inline QString &QString::prepend( const QByteArray & s )
797{ return insert(0,s.data()); } 822{ return insert(0,QString(s)); }
823#endif
824
825#ifndef QT_NO_STL
826inline QString &QString::prepend( const std::string& s )
827{ return insert(0, s); }
828#endif
829
830#ifndef QT_NO_CAST_ASCII
831inline QString &QString::operator+=( const QByteArray &s )
832{ return operator+=(QString(s)); }
798#endif 833#endif
799 834
800inline QString &QString::append( const QString & s ) 835inline QString &QString::append( const QString & s )
801{ return operator+=(s); } 836{ return operator+=(s); }
802 837
803#ifndef QT_NO_CAST_ASCII 838#ifndef QT_NO_CAST_ASCII
804inline QString &QString::append( const QByteArray &s ) 839inline QString &QString::append( const QByteArray &s )
805{ return operator+=(s.data()); } 840{ return operator+=(s); }
806 841
807inline QString &QString::append( const char * s ) 842inline QString &QString::append( const char * s )
808{ return operator+=(s); } 843{ return operator+=(s); }
809#endif 844#endif
810 845
811inline QString &QString::append( QChar c ) 846inline QString &QString::append( QChar c )
812{ return operator+=(c); } 847{ return operator+=(c); }
813 848
814inline QString &QString::append( char c ) 849inline QString &QString::append( char c )
815{ return operator+=(c); } 850{ return operator+=(c); }
816 851
817#ifndef QT_NO_CAST_ASCII 852#ifndef QT_NO_STL
818inline QString &QString::operator+=( const QByteArray &s ) 853inline QString &QString::operator+=( const std::string& s )
819{ return operator+=(s.data()); } 854{ return operator+=(s.c_str()); }
855inline QString &QString::append( const std::string& s )
856{ return operator+=(s); }
820#endif 857#endif
821 858
822inline QString &QString::setNum( short n, int base ) 859inline QString &QString::setNum( short n, int base )
823{ return setNum((long)n, base); } 860{ return setNum((long)n, base); }
824 861
825inline QString &QString::setNum( ushort n, int base ) 862inline QString &QString::setNum( ushort n, int base )
826{ return setNum((ulong)n, base); } 863{ return setNum((ulong)n, base); }
827 864
828inline QString &QString::setNum( int n, int base ) 865inline QString &QString::setNum( int n, int base )
829{ return setNum((long)n, base); } 866{ return setNum((long)n, base); }
830 867
831inline QString &QString::setNum( uint n, int base ) 868inline QString &QString::setNum( uint n, int base )
832{ return setNum((ulong)n, base); } 869{ return setNum((ulong)n, base); }
833 870
834inline QString &QString::setNum( float n, char f, int prec ) 871inline QString &QString::setNum( float n, char f, int prec )
835{ return setNum((double)n,f,prec); } 872{ return setNum((double)n,f,prec); }
836 873
837inline QString QString::arg(int a, int fieldwidth, int base) const 874inline QString QString::arg(int a, int fieldwidth, int base) const
838{ return arg((long)a, fieldwidth, base); } 875{ return arg((long)a, fieldwidth, base); }
839 876
840inline QString QString::arg(uint a, int fieldwidth, int base) const 877inline QString QString::arg(uint a, int fieldwidth, int base) const
841{ return arg((ulong)a, fieldwidth, base); } 878{ return arg((ulong)a, fieldwidth, base); }
842 879
843inline QString QString::arg(short a, int fieldwidth, int base) const 880inline QString QString::arg(short a, int fieldwidth, int base) const
844{ return arg((long)a, fieldwidth, base); } 881{ return arg((long)a, fieldwidth, base); }
845 882
846inline QString QString::arg(ushort a, int fieldwidth, int base) const 883inline QString QString::arg(ushort a, int fieldwidth, int base) const
847{ return arg((ulong)a, fieldwidth, base); } 884{ return arg((ulong)a, fieldwidth, base); }
848 885
849inline int QString::find( char c, int index, bool cs ) const 886inline int QString::find( char c, int index, bool cs ) const
850{ return find(QChar(c), index, cs); } 887{ return find(QChar(c), index, cs); }
851 888
852inline int QString::findRev( char c, int index, bool cs) const 889inline int QString::findRev( char c, int index, bool cs) const
853{ return findRev( QChar(c), index, cs ); } 890{ return findRev( QChar(c), index, cs ); }
854 891
855#ifndef QT_NO_CAST_ASCII 892#ifndef QT_NO_CAST_ASCII
856inline int QString::find( const char* str, int index ) const 893inline int QString::find( const char* str, int index ) const
857{ return find(QString::fromLatin1(str), index); } 894{ return find(QString::fromAscii(str), index); }
858 895
859inline int QString::findRev( const char* str, int index ) const 896inline int QString::findRev( const char* str, int index ) const
860{ return findRev(QString::fromLatin1(str), index); } 897{ return findRev(QString::fromAscii(str), index); }
861#endif 898#endif
862 899
863 900
864/***************************************************************************** 901/*****************************************************************************
865 QString non-member operators 902 QString non-member operators
866 *****************************************************************************/ 903 *****************************************************************************/
867 904
868Q_EXPORT bool operator!=( const QString &s1, const QString &s2 ); 905Q_EXPORT bool operator!=( const QString &s1, const QString &s2 );
869Q_EXPORT bool operator<( const QString &s1, const QString &s2 ); 906Q_EXPORT bool operator<( const QString &s1, const QString &s2 );
870Q_EXPORT bool operator<=( const QString &s1, const QString &s2 ); 907Q_EXPORT bool operator<=( const QString &s1, const QString &s2 );
871Q_EXPORT bool operator==( const QString &s1, const QString &s2 ); 908Q_EXPORT bool operator==( const QString &s1, const QString &s2 );
872Q_EXPORT bool operator>( const QString &s1, const QString &s2 ); 909Q_EXPORT bool operator>( const QString &s1, const QString &s2 );
873Q_EXPORT bool operator>=( const QString &s1, const QString &s2 ); 910Q_EXPORT bool operator>=( const QString &s1, const QString &s2 );
874#ifndef QT_NO_CAST_ASCII 911#ifndef QT_NO_CAST_ASCII
875Q_EXPORT bool operator!=( const QString &s1, const char *s2 ); 912Q_EXPORT bool operator!=( const QString &s1, const char *s2 );
876Q_EXPORT bool operator<( const QString &s1, const char *s2 ); 913Q_EXPORT bool operator<( const QString &s1, const char *s2 );
877Q_EXPORT bool operator<=( const QString &s1, const char *s2 ); 914Q_EXPORT bool operator<=( const QString &s1, const char *s2 );
878Q_EXPORT bool operator==( const QString &s1, const char *s2 ); 915Q_EXPORT bool operator==( const QString &s1, const char *s2 );
879Q_EXPORT bool operator>( const QString &s1, const char *s2 ); 916Q_EXPORT bool operator>( const QString &s1, const char *s2 );
880Q_EXPORT bool operator>=( const QString &s1, const char *s2 ); 917Q_EXPORT bool operator>=( const QString &s1, const char *s2 );
881Q_EXPORT bool operator!=( const char *s1, const QString &s2 ); 918Q_EXPORT bool operator!=( const char *s1, const QString &s2 );
882Q_EXPORT bool operator<( const char *s1, const QString &s2 ); 919Q_EXPORT bool operator<( const char *s1, const QString &s2 );
883Q_EXPORT bool operator<=( const char *s1, const QString &s2 ); 920Q_EXPORT bool operator<=( const char *s1, const QString &s2 );
884Q_EXPORT bool operator==( const char *s1, const QString &s2 ); 921Q_EXPORT bool operator==( const char *s1, const QString &s2 );
885//Q_EXPORT bool operator>( const char *s1, const QString &s2 ); // MSVC++ 922//Q_EXPORT bool operator>( const char *s1, const QString &s2 ); // MSVC++
886Q_EXPORT bool operator>=( const char *s1, const QString &s2 ); 923Q_EXPORT bool operator>=( const char *s1, const QString &s2 );
887#endif 924#endif
888 925
889Q_EXPORT inline const QString operator+( const QString &s1, const QString &s2 ) 926Q_EXPORT inline const QString operator+( const QString &s1, const QString &s2 )
890{ 927{
891 QString tmp( s1 ); 928 QString tmp( s1 );
892 tmp += s2; 929 tmp += s2;
893 return tmp; 930 return tmp;
894} 931}
895 932
896#ifndef QT_NO_CAST_ASCII 933#ifndef QT_NO_CAST_ASCII
897Q_EXPORT inline const QString operator+( const QString &s1, const char *s2 ) 934Q_EXPORT inline const QString operator+( const QString &s1, const char *s2 )
898{ 935{
899 QString tmp( s1 ); 936 QString tmp( s1 );
900 tmp += QString::fromLatin1(s2); 937 tmp += QString::fromAscii(s2);
901 return tmp; 938 return tmp;
902} 939}
903 940
904Q_EXPORT inline const QString operator+( const char *s1, const QString &s2 ) 941Q_EXPORT inline const QString operator+( const char *s1, const QString &s2 )
905{ 942{
906 QString tmp = QString::fromLatin1( s1 ); 943 QString tmp = QString::fromAscii( s1 );
907 tmp += s2; 944 tmp += s2;
908 return tmp; 945 return tmp;
909} 946}
910#endif 947#endif
911 948
912Q_EXPORT inline const QString operator+( const QString &s1, QChar c2 ) 949Q_EXPORT inline const QString operator+( const QString &s1, QChar c2 )
913{ 950{
914 QString tmp( s1 ); 951 QString tmp( s1 );
915 tmp += c2; 952 tmp += c2;
916 return tmp; 953 return tmp;
917} 954}
918 955
919Q_EXPORT inline const QString operator+( const QString &s1, char c2 ) 956Q_EXPORT inline const QString operator+( const QString &s1, char c2 )
920{ 957{
921 QString tmp( s1 ); 958 QString tmp( s1 );
922 tmp += c2; 959 tmp += c2;
923 return tmp; 960 return tmp;
924} 961}
925 962
926Q_EXPORT inline const QString operator+( QChar c1, const QString &s2 ) 963Q_EXPORT inline const QString operator+( QChar c1, const QString &s2 )
927{ 964{
928 QString tmp; 965 QString tmp;
929 tmp += c1; 966 tmp += c1;
930 tmp += s2; 967 tmp += s2;
931 return tmp; 968 return tmp;
932} 969}
933 970
934Q_EXPORT inline const QString operator+( char c1, const QString &s2 ) 971Q_EXPORT inline const QString operator+( char c1, const QString &s2 )
935{ 972{
936 QString tmp; 973 QString tmp;
937 tmp += c1; 974 tmp += c1;
938 tmp += s2; 975 tmp += s2;
939 return tmp; 976 return tmp;
940} 977}
941 978
942#if defined(Q_OS_WIN32) 979#if defined(Q_OS_WIN32)
943extern Q_EXPORT QString qt_winQString(void*); 980extern Q_EXPORT QString qt_winQString(void*);
944extern Q_EXPORT const void* qt_winTchar(const QString& str, bool addnul); 981extern Q_EXPORT const void* qt_winTchar(const QString& str, bool addnul);
945extern Q_EXPORT void* qt_winTchar_new(const QString& str); 982extern Q_EXPORT void* qt_winTchar_new(const QString& str);
946extern Q_EXPORT QCString qt_winQString2MB( const QString& s, int len=-1 ); 983extern Q_EXPORT QCString qt_winQString2MB( const QString& s, int len=-1 );
947extern Q_EXPORT QString qt_winMB2QString( const char* mb, int len=-1 ); 984extern Q_EXPORT QString qt_winMB2QString( const char* mb, int len=-1 );
948#endif 985#endif
949 986
987#ifdef QT_QWINEXPORT
988#define Q_DEFINED_QSTRING
989#include "qwinexport.h"
990#endif /* QT_QWINEXPORT */
950#endif // QSTRING_H 991#endif // QSTRING_H