summaryrefslogtreecommitdiff
path: root/qmake/include/qstring.h
Side-by-side diff
Diffstat (limited to 'qmake/include/qstring.h') (more/less context) (ignore 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 @@
/****************************************************************************
** $Id$
**
-** Definition of the QString class, and related Unicode
-** functions.
+** Definition of the QString class, and related Unicode functions.
**
** Created : 920609
**
-** Copyright (C) 1992-2000 Trolltech AS. All rights reserved.
+** Copyright (C) 1992-2002 Trolltech AS. All rights reserved.
**
** This file is part of the tools module of the Qt GUI Toolkit.
**
** This file may be distributed under the terms of the Q Public License
** as defined by Trolltech AS of Norway and appearing in the file
** LICENSE.QPL included in the packaging of this file.
@@ -40,12 +39,19 @@
#define QSTRING_H
#ifndef QT_H
#include "qcstring.h"
#endif // QT_H
+#ifndef QT_NO_STL
+#include <string>
+#if defined(Q_WRONG_SB_CTYPE_MACROS) && defined(_SB_CTYPE_MACROS)
+#undef _SB_CTYPE_MACROS
+#endif
+#endif
+
/*****************************************************************************
QString class
*****************************************************************************/
class QRegExp;
@@ -333,40 +339,40 @@ inline bool operator>( QChar c, char ch ) { return !(ch>=c); }
inline bool operator>( char ch, QChar c ) { return !(c>=ch); }
inline bool operator>( QChar c1, QChar c2 ) { return !(c2>=c1); }
// internal
struct Q_EXPORT QStringData : public QShared {
QStringData() :
- QShared(), unicode(0), ascii(0), len(0), simpletext(1), maxl(0), dirty(0) { ref(); }
+ QShared(), unicode(0), ascii(0), len(0), issimpletext(TRUE), maxl(0), islatin1(FALSE) { ref(); }
QStringData(QChar *u, uint l, uint m) :
- QShared(), unicode(u), ascii(0), len(l), simpletext(1), maxl(m), dirty(1) { }
+ QShared(), unicode(u), ascii(0), len(l), issimpletext(FALSE), maxl(m), islatin1(FALSE) { }
~QStringData() { if ( unicode ) delete[] ((char*)unicode);
if ( ascii ) delete[] ascii; }
void deleteSelf();
QChar *unicode;
char *ascii;
void setDirty() {
if ( ascii ) {
delete [] ascii;
ascii = 0;
}
- dirty = 1;
+ issimpletext = FALSE;
}
#ifdef Q_OS_MAC9
uint len;
#else
uint len : 30;
#endif
- uint simpletext : 1;
+ uint issimpletext : 1;
#ifdef Q_OS_MAC9
uint maxl;
#else
uint maxl : 30;
#endif
- uint dirty : 1;
+ uint islatin1 : 1;
private:
#if defined(Q_DISABLE_COPY)
QStringData( const QStringData& );
QStringData& operator=( const QStringData& );
#endif
@@ -381,17 +387,21 @@ public:
QString( const QString & ); // impl-shared copy
QString( const QByteArray& ); // deep copy
QString( const QChar* unicode, uint length ); // deep copy
#ifndef QT_NO_CAST_ASCII
QString( const char *str ); // deep copy
#endif
+#ifndef QT_NO_STL
+ QString( const std::string& ); // deep copy
+#endif
~QString();
QString &operator=( const QString & ); // impl-shared copy
-#ifndef QT_NO_CAST_ASCII
QString &operator=( const char * ); // deep copy
+#ifndef QT_NO_STL
+ QString &operator=( const std::string& ); // deep copy
#endif
QString &operator=( const QCString& ); // deep copy
QString &operator=( QChar c );
QString &operator=( char c );
QT_STATIC_CONST QString null;
@@ -491,19 +501,25 @@ public:
QString &append( QChar );
QString &append( const QString & );
#ifndef QT_NO_CAST_ASCII
QString &append( const QByteArray & );
QString &append( const char * );
#endif
+#ifndef QT_NO_STL
+ QString &append( const std::string& );
+#endif
QString &prepend( char );
QString &prepend( QChar );
QString &prepend( const QString & );
#ifndef QT_NO_CAST_ASCII
QString &prepend( const QByteArray & );
QString &prepend( const char * );
#endif
+#ifndef QT_NO_STL
+ QString &prepend( const std::string& );
+#endif
QString &remove( uint index, uint len );
QString &remove( QChar c );
QString &remove( char c ) { return remove( QChar(c) ); }
QString &remove( const QString & );
#ifndef QT_NO_REGEXP
QString &remove( const QRegExp & );
@@ -553,12 +569,15 @@ public:
QString &operator+=( const QString &str );
#ifndef QT_NO_CAST_ASCII
QString &operator+=( const QByteArray &str );
QString &operator+=( const char *str );
#endif
+#ifndef QT_NO_STL
+ QString &operator+=( const std::string& );
+#endif
QString &operator+=( QChar c );
QString &operator+=( char c );
QChar at( uint i ) const
{ return i < d->len ? d->unicode[i] : QChar::null; }
QChar operator[]( int i ) const { return at((uint)i); }
@@ -573,28 +592,34 @@ public:
subat( i );
d->setDirty();
return d->unicode[i];
}
const QChar* unicode() const { return d->unicode; }
- const char* ascii() const { return latin1(); }
+ const char* ascii() const;
+ static QString fromAscii(const char*, int len=-1);
const char* latin1() const;
static QString fromLatin1(const char*, int len=-1);
QCString utf8() const;
static QString fromUtf8(const char*, int len=-1);
QCString local8Bit() const;
static QString fromLocal8Bit(const char*, int len=-1);
bool operator!() const;
#ifndef QT_NO_ASCII_CAST
- operator const char *() const { return latin1(); }
+ operator const char *() const { return ascii(); }
#endif
+#ifndef QT_NO_STL
+ operator std::string() const { return ascii() ? ascii() : ""; }
+#endif
+
static QString fromUcs2( const unsigned short *ucs2 );
const unsigned short *ucs2() const;
QString &setUnicode( const QChar* unicode, uint len );
QString &setUnicodeCodes( const ushort* unicode_as_ushorts, uint len );
+ QString &setAscii( const char*, int len=-1 );
QString &setLatin1( const char*, int len=-1 );
int compare( const QString& s ) const;
static int compare( const QString& s1, const QString& s2 )
{ return s1.compare( s2 ); }
@@ -606,21 +631,21 @@ public:
friend Q_EXPORT QDataStream &operator>>( QDataStream &, QString & );
#endif
void compose();
#ifndef QT_NO_COMPAT
- const char* data() const { return latin1(); }
+ const char* data() const { return ascii(); }
#endif
bool startsWith( const QString& ) const;
bool endsWith( const QString& ) const;
void setLength( uint newLength );
- bool simpleText() const { if ( d->dirty ) checkSimpleText(); return (bool)d->simpletext; }
+ bool simpleText() const { if ( !d->issimpletext ) checkSimpleText(); return (bool)d->issimpletext; }
bool isRightToLeft() const;
private:
QString( int size, bool /* dummy */ ); // allocate size incl. \0
@@ -628,15 +653,15 @@ private:
void real_detach();
void subat( uint );
bool findArg(int& pos, int& len) const;
void checkSimpleText() const;
- static QChar* asciiToUnicode( const char*, uint * len, uint maxlen=(uint)-1 );
- static QChar* asciiToUnicode( const QByteArray&, uint * len );
- static char* unicodeToAscii( const QChar*, uint len );
+ static QChar* latin1ToUnicode( const char*, uint * len, uint maxlen=(uint)-1 );
+ static QChar* latin1ToUnicode( const QByteArray&, uint * len );
+ static char* unicodeToLatin1( const QChar*, uint len );
QStringData *d;
static QStringData* shared_null;
static QStringData* makeSharedNull();
friend class QConstString;
@@ -791,35 +816,47 @@ inline QString &QString::prepend( QChar c )
inline QString &QString::prepend( char c )
{ return insert(0,c); }
#ifndef QT_NO_CAST_ASCII
inline QString &QString::prepend( const QByteArray & s )
-{ return insert(0,s.data()); }
+{ return insert(0,QString(s)); }
+#endif
+
+#ifndef QT_NO_STL
+inline QString &QString::prepend( const std::string& s )
+{ return insert(0, s); }
+#endif
+
+#ifndef QT_NO_CAST_ASCII
+inline QString &QString::operator+=( const QByteArray &s )
+{ return operator+=(QString(s)); }
#endif
inline QString &QString::append( const QString & s )
{ return operator+=(s); }
#ifndef QT_NO_CAST_ASCII
inline QString &QString::append( const QByteArray &s )
-{ return operator+=(s.data()); }
+{ return operator+=(s); }
inline QString &QString::append( const char * s )
{ return operator+=(s); }
#endif
inline QString &QString::append( QChar c )
{ return operator+=(c); }
inline QString &QString::append( char c )
{ return operator+=(c); }
-#ifndef QT_NO_CAST_ASCII
-inline QString &QString::operator+=( const QByteArray &s )
-{ return operator+=(s.data()); }
+#ifndef QT_NO_STL
+inline QString &QString::operator+=( const std::string& s )
+{ return operator+=(s.c_str()); }
+inline QString &QString::append( const std::string& s )
+{ return operator+=(s); }
#endif
inline QString &QString::setNum( short n, int base )
{ return setNum((long)n, base); }
inline QString &QString::setNum( ushort n, int base )
@@ -851,16 +888,16 @@ inline int QString::find( char c, int index, bool cs ) const
inline int QString::findRev( char c, int index, bool cs) const
{ return findRev( QChar(c), index, cs ); }
#ifndef QT_NO_CAST_ASCII
inline int QString::find( const char* str, int index ) const
-{ return find(QString::fromLatin1(str), index); }
+{ return find(QString::fromAscii(str), index); }
inline int QString::findRev( const char* str, int index ) const
-{ return findRev(QString::fromLatin1(str), index); }
+{ return findRev(QString::fromAscii(str), index); }
#endif
/*****************************************************************************
QString non-member operators
*****************************************************************************/
@@ -894,19 +931,19 @@ Q_EXPORT inline const QString operator+( const QString &s1, const QString &s2 )
}
#ifndef QT_NO_CAST_ASCII
Q_EXPORT inline const QString operator+( const QString &s1, const char *s2 )
{
QString tmp( s1 );
- tmp += QString::fromLatin1(s2);
+ tmp += QString::fromAscii(s2);
return tmp;
}
Q_EXPORT inline const QString operator+( const char *s1, const QString &s2 )
{
- QString tmp = QString::fromLatin1( s1 );
+ QString tmp = QString::fromAscii( s1 );
tmp += s2;
return tmp;
}
#endif
Q_EXPORT inline const QString operator+( const QString &s1, QChar c2 )
@@ -944,7 +981,11 @@ extern Q_EXPORT QString qt_winQString(void*);
extern Q_EXPORT const void* qt_winTchar(const QString& str, bool addnul);
extern Q_EXPORT void* qt_winTchar_new(const QString& str);
extern Q_EXPORT QCString qt_winQString2MB( const QString& s, int len=-1 );
extern Q_EXPORT QString qt_winMB2QString( const char* mb, int len=-1 );
#endif
+#ifdef QT_QWINEXPORT
+#define Q_DEFINED_QSTRING
+#include "qwinexport.h"
+#endif /* QT_QWINEXPORT */
#endif // QSTRING_H