summaryrefslogtreecommitdiffstats
path: root/src/tools
diff options
context:
space:
mode:
authorSlávek Banko <[email protected]>2019-02-04 17:16:04 +0100
committerSlávek Banko <[email protected]>2019-02-10 11:22:13 +0100
commitd90d84170f100b8c7c96b31eb974c91928800850 (patch)
tree3fdec0b2fcd6420d3bbac34d8037c5becbe0aaae /src/tools
parent77f96ad32807824272cf2099f87fbc5a4c8c48b6 (diff)
downloadtqt3-d90d84170f100b8c7c96b31eb974c91928800850.tar.gz
tqt3-d90d84170f100b8c7c96b31eb974c91928800850.zip
Make use of TQString::utf8() and TQString::local8Bit() safe for conversion to char*.
Signed-off-by: Slávek Banko <[email protected]> (cherry picked from commit 4e83f4f200f4832280808796694495ebb20070b6)
Diffstat (limited to 'src/tools')
-rw-r--r--src/tools/ntqstring.h1
-rw-r--r--src/tools/qstring.cpp34
2 files changed, 27 insertions, 8 deletions
diff --git a/src/tools/ntqstring.h b/src/tools/ntqstring.h
index 4d473e016..bfa88b80e 100644
--- a/src/tools/ntqstring.h
+++ b/src/tools/ntqstring.h
@@ -384,6 +384,7 @@ struct Q_EXPORT TQStringData : public TQShared {
bool security_unpaged : 1;
TQMutex* mutex;
+ TQCString *cString;
private:
#if defined(TQ_DISABLE_COPY)
diff --git a/src/tools/qstring.cpp b/src/tools/qstring.cpp
index 67de50301..0b188e3a9 100644
--- a/src/tools/qstring.cpp
+++ b/src/tools/qstring.cpp
@@ -1051,7 +1051,8 @@ TQStringData::TQStringData() : TQShared(),
issimpletext(TRUE),
maxl(0),
islatin1(FALSE),
- security_unpaged(FALSE) {
+ security_unpaged(FALSE),
+ cString(0) {
#if defined(QT_THREAD_SUPPORT) && defined(MAKE_TQSTRING_THREAD_SAFE)
mutex = new TQMutex(FALSE);
#endif // QT_THREAD_SUPPORT && MAKE_TQSTRING_THREAD_SAFE
@@ -1065,7 +1066,8 @@ TQStringData::TQStringData(TQChar *u, uint l, uint m) : TQShared(),
issimpletext(FALSE),
maxl(m),
islatin1(FALSE),
- security_unpaged(FALSE) {
+ security_unpaged(FALSE),
+ cString(0) {
#if defined(QT_THREAD_SUPPORT) && defined(MAKE_TQSTRING_THREAD_SAFE)
mutex = new TQMutex(FALSE);
#endif // QT_THREAD_SUPPORT && MAKE_TQSTRING_THREAD_SAFE
@@ -1083,6 +1085,9 @@ TQStringData::~TQStringData() {
if ( ascii ) {
delete[] ascii;
}
+ if (cString) {
+ delete cString;
+ }
#if defined(QT_THREAD_SUPPORT) && defined(MAKE_TQSTRING_THREAD_SAFE)
if ( mutex ) {
delete mutex;
@@ -1096,6 +1101,10 @@ void TQStringData::setDirty() {
delete [] ascii;
ascii = 0;
}
+ if (cString) {
+ delete cString;
+ cString = 0;
+ }
issimpletext = FALSE;
}
@@ -6026,6 +6035,10 @@ TQCString TQString::utf8() const
++ch;
}
rstr.truncate( cursor - (uchar*)rstr.data() );
+ if (!d->cString) {
+ d->cString = new TQCString;
+ }
+ *d->cString = rstr;
return rstr;
}
@@ -6227,23 +6240,28 @@ TQString TQString::fromLatin1( const char* chars, int len )
TQCString TQString::local8Bit() const
{
+ if (!d->cString) {
+ d->cString = new TQCString;
+ }
#ifdef QT_NO_TEXTCODEC
- return latin1();
+ *d->cString = TQCString(latin1());
+ return *d->cString;
#else
#ifdef Q_WS_X11
TQTextCodec* codec = TQTextCodec::codecForLocale();
- return codec
- ? codec->fromUnicode(*this)
- : TQCString(latin1());
+ *d->cString = codec ? codec->fromUnicode(*this) : TQCString(latin1());
+ return *d->cString;
#endif
#if defined( Q_WS_MACX )
return utf8();
#endif
#if defined( Q_WS_MAC9 )
- return TQCString(latin1()); //I'm evil..
+ *d->cString = TQCString(latin1()); //I'm evil..
+ return *d->cString;
#endif
#ifdef Q_WS_WIN
- return isNull() ? TQCString("") : qt_winTQString2MB( *this );
+ *d->cString = isNull() ? TQCString("") : qt_winTQString2MB( *this );
+ return *d->cString;
#endif
#ifdef Q_WS_QWS
return utf8(); // ### if there is any 8 bit format supported?