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,15 +1,14 @@
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.
@@ -40,12 +39,19 @@
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;
@@ -333,40 +339,40 @@ inline 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
@@ -381,17 +387,21 @@ public:
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;
@@ -491,19 +501,25 @@ public:
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 & );
@@ -553,12 +569,15 @@ public:
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); }
@@ -573,28 +592,34 @@ public:
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
@@ -606,21 +631,21 @@ public:
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
@@ -628,15 +653,15 @@ private:
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;
@@ -791,35 +816,47 @@ inline QString &QString::prepend( QChar 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 )
@@ -851,16 +888,16 @@ inline int QString::find( char c, int index, bool cs ) const
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 *****************************************************************************/
@@ -894,19 +931,19 @@ Q_EXPORT inline const QString operator+( const QString &s1, const QString &s2 )
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 )
@@ -944,7 +981,11 @@ extern 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