diff options
author | Slávek Banko <slavek.banko@axis.cz> | 2019-02-10 11:25:02 +0100 |
---|---|---|
committer | Slávek Banko <slavek.banko@axis.cz> | 2019-02-10 11:25:02 +0100 |
commit | 0a1966b25e36fbca6263b656fec8de9d42770f8d (patch) | |
tree | 4e8e434ae121c74b563ae228de5d013c8571ae29 | |
parent | 26c3a9ba485e00c1035b4a785122d53f82a4fde0 (diff) | |
download | qt3-0a1966b25e36fbca6263b656fec8de9d42770f8d.tar.gz qt3-0a1966b25e36fbca6263b656fec8de9d42770f8d.zip |
Make use of QString::utf8() and QString::local8Bit() safe for conversion to char*.
Signed-off-by: Slávek Banko <slavek.banko@axis.cz>
-rw-r--r-- | src/tools/qstring.cpp | 34 | ||||
-rw-r--r-- | src/tools/qstring.h | 1 |
2 files changed, 27 insertions, 8 deletions
diff --git a/src/tools/qstring.cpp b/src/tools/qstring.cpp index 1288fd7..143f80c 100644 --- a/src/tools/qstring.cpp +++ b/src/tools/qstring.cpp @@ -1052,7 +1052,8 @@ QStringData::QStringData() : QShared(), issimpletext(TRUE), maxl(0), islatin1(FALSE), - security_unpaged(FALSE) { + security_unpaged(FALSE), + cString(0) { #if defined(QT_THREAD_SUPPORT) && defined(MAKE_QSTRING_THREAD_SAFE) mutex = new QMutex(FALSE); #endif // QT_THREAD_SUPPORT && MAKE_QSTRING_THREAD_SAFE @@ -1066,7 +1067,8 @@ QStringData::QStringData(QChar *u, uint l, uint m) : QShared(), issimpletext(FALSE), maxl(m), islatin1(FALSE), - security_unpaged(FALSE) { + security_unpaged(FALSE), + cString(0) { #if defined(QT_THREAD_SUPPORT) && defined(MAKE_QSTRING_THREAD_SAFE) mutex = new QMutex(FALSE); #endif // QT_THREAD_SUPPORT && MAKE_QSTRING_THREAD_SAFE @@ -1084,6 +1086,9 @@ QStringData::~QStringData() { if ( ascii ) { delete[] ascii; } + if (cString) { + delete cString; + } #if defined(QT_THREAD_SUPPORT) && defined(MAKE_QSTRING_THREAD_SAFE) if ( mutex ) { delete mutex; @@ -1097,6 +1102,10 @@ void QStringData::setDirty() { delete [] ascii; ascii = 0; } + if (cString) { + delete cString; + cString = 0; + } issimpletext = FALSE; } @@ -6034,6 +6043,10 @@ QCString QString::utf8() const ++ch; } rstr.truncate( cursor - (uchar*)rstr.data() ); + if (!d->cString) { + d->cString = new QCString; + } + *d->cString = rstr; return rstr; } @@ -6235,23 +6248,28 @@ QString QString::fromLatin1( const char* chars, int len ) QCString QString::local8Bit() const { + if (!d->cString) { + d->cString = new QCString; + } #ifdef QT_NO_TEXTCODEC - return latin1(); + *d->cString = QCString(latin1()); + return *d->cString; #else #ifdef Q_WS_X11 QTextCodec* codec = QTextCodec::codecForLocale(); - return codec - ? codec->fromUnicode(*this) - : QCString(latin1()); + *d->cString = codec ? codec->fromUnicode(*this) : QCString(latin1()); + return *d->cString; #endif #if defined( Q_WS_MACX ) return utf8(); #endif #if defined( Q_WS_MAC9 ) - return QCString(latin1()); //I'm evil.. + *d->cString = QCString(latin1()); //I'm evil.. + return *d->cString; #endif #ifdef Q_WS_WIN - return isNull() ? QCString("") : qt_winQString2MB( *this ); + *d->cString = isNull() ? QCString("") : qt_winQString2MB( *this ); + return *d->cString; #endif #ifdef Q_WS_QWS return utf8(); // ### if there is any 8 bit format supported? diff --git a/src/tools/qstring.h b/src/tools/qstring.h index 82b8a0e..19408a7 100644 --- a/src/tools/qstring.h +++ b/src/tools/qstring.h @@ -388,6 +388,7 @@ struct Q_EXPORT QStringData : public QShared { bool security_unpaged : 1; QMutex* mutex; + QCString *cString; private: #if defined(Q_DISABLE_COPY) |