diff -Naur qt-x11-free-3.0.2.orig/src/tools/qstring.cpp qt-x11-free-3.0.2/src/tools/qstring.cpp --- qt-x11-free-3.0.2.orig/src/tools/qstring.cpp Tue Mar 12 20:11:56 2002 +++ qt-x11-free-3.0.2/src/tools/qstring.cpp Tue Mar 12 20:18:00 2002 @@ -11521,12 +11521,42 @@ Constructs a QChar corresponding to ASCII/Latin1 character \a c. */ +QChar::QChar( char c ) +{ +#ifdef QT_NO_TEXTCODEC + ucs = (uchar)c; +#else + if ( (uchar)c > 127 ) { // Not US-ASCII character we should use TextCodec + ucs = QString::fromLocal8Bit( (const char *) & c, 1 ).at(0).unicode(); + } + else + ucs = (uchar)c; // For US-ASCII character simple assignment +#endif // QT_NO_TEXTCODEC +#ifdef QT_QSTRING_UCS_4 + grp = 0; +#endif +} /*! \fn QChar::QChar( uchar c ) Constructs a QChar corresponding to ASCII/Latin1 character \a c. */ +QChar::QChar( uchar c ) +{ +#ifdef QT_NO_TEXTCODEC + ucs = c; +#else + if ( c > 127 ) { // Not US-ASCII character we should use TextCodec + ucs = QString::fromLocal8Bit( (const char *) & c, 1 ).at(0).unicode(); + } + else + ucs = c; // For US-ASCII character simple assignment +#endif // QT_NO_TEXTCODEC +#ifdef QT_QSTRING_UCS_4 + grp = 0; +#endif +} /*! \fn QChar::QChar( uchar c, uchar r ) @@ -12277,8 +12307,11 @@ QChar *result = uc; if ( len ) *len = l; - while (l--) - *uc++ = *str++; + while (l--) { + uc->setCell( *str++ ); + uc->setRow( 0 ); + *uc++; + } return result; } @@ -12296,8 +12329,11 @@ QChar *result = uc; if ( len ) *len = l; - while (l--) - *uc++ = *str++; + while (l--) { + uc->setCell( *str++ ); + uc->setRow( 0 ); + *uc++; + } return result; } @@ -12325,8 +12361,11 @@ QChar *uc = new QChar[ l ]; // Can't use macro since function is public result = uc; uint i = l; - while ( i-- ) - *uc++ = *str++; + while (i--) { + uc->setCell( *str++ ); + uc->setRow( 0 ); + *uc++; + } } if ( len ) *len = l; @@ -12349,8 +12388,11 @@ QChar *uc = QT_ALLOC_QCHAR_VEC( l ); result = uc; uint i = l; - while ( i-- ) - *uc++ = *str++; + while (i--) { + uc->setCell( *str++ ); + uc->setRow( 0 ); + *uc++; + } } if ( len ) *len = l; @@ -12368,6 +12410,7 @@ if (!uc) { return 0; } +#ifdef QT_NO_TEXTCODEC char *a = new char[l+1]; char *result = a; while (l--) { @@ -12377,6 +12420,9 @@ } *a = '\0'; return result; +#else + return qstrdup(QString(uc,l).local8Bit().data()); +#endif // QT_NO_TEXTCODEC } /***************************************************************************** @@ -12704,7 +12750,7 @@ void QString::deref() { - if ( d->deref() ) { + if ( d && d->deref() ) { if ( d == shared_null ) shared_null = 0; delete d; @@ -12750,7 +12796,7 @@ */ QString &QString::operator=( const QCString& cs ) { - return setLatin1(cs); + return setLatin1(cs.data()); } @@ -15271,6 +15317,17 @@ Returns a latin-1 copy of this character, if this character is in the latin-1 character set. If not, this function returns 0. */ +char QChar::latin1() const +{ +#ifdef QT_NO_TEXTCODEC + return ucs > 0xff ? 0 : (char) ucs; +#else + if ( ucs > 0xff ) { // Non ISO-8859-1 character we should use TextCodec + return QString(*this).local8Bit().at(0); + } + return (char) ucs; +#endif // QT_NO_TEXTCODEC +} /*! @@ -15292,7 +15349,11 @@ if ( !d->ascii ) { Q2HELPER(stat_get_ascii++) Q2HELPER(stat_get_ascii_size+=d->len) +#ifdef QT_NO_TEXTCODEC d->ascii = unicodeToAscii( d->unicode, d->len ); +#else + if( d->unicode ) d->ascii = qstrdup(local8Bit().data()); +#endif } return d->ascii; } @@ -15315,9 +15376,8 @@ QCString QString::utf8() const { static QTextCodec* codec = QTextCodec::codecForMib(106); - return codec - ? codec->fromUnicode(*this) - : QCString(latin1()); + if ( !codec ) codec = QTextCodec::codecForMib(4); // Use ISO-8859-1 codec + return codec->fromUnicode(*this); } /*! @@ -15337,7 +15397,8 @@ { static QTextCodec* codec = QTextCodec::codecForMib( 106 ); if ( len < 0 ) len = qstrlen( utf8 ); - return codec ? codec->toUnicode( utf8, len ) : fromLatin1( utf8, len ); + if ( !codec ) codec = QTextCodec::codecForMib(4); // Use ISO-8859-1 codec + return codec->toUnicode( utf8, len ); } #endif // QT_NO_TEXTCODEC @@ -15360,6 +15421,7 @@ */ QString QString::fromLatin1( const char* chars, int len ) { +#ifdef QT_NO_TEXTCODEC uint l; QChar *uc; if ( len < 0 ) { @@ -15368,6 +15430,9 @@ uc = internalAsciiToUnicode( chars, &l, len ); } return QString( new QStringData(uc, l, l), TRUE ); +#else + return QString::fromLocal8Bit( chars, len ); +#endif // QT_NO_TEXTCODEC } /*! @@ -15393,24 +15458,18 @@ #ifdef QT_NO_TEXTCODEC return latin1(); #else -#ifdef Q_WS_X11 - QTextCodec* codec = QTextCodec::codecForLocale(); - return codec - ? codec->fromUnicode(*this) - : QCString(latin1()); -#endif -#if defined( Q_WS_MACX ) - return utf8(); +#if defined( Q_WS_X11 ) || defined( Q_WS_MACX ) || defined( Q_WS_QWS ) +#if defined( Q_WS_MACX ) || defined( Q_WS_QWS ) + static QTextCodec *codec = QTextCodec::codecForMib(106); // Use UTF8 codec +#else + static QTextCodec* codec = QTextCodec::codecForLocale(); #endif -#if defined( Q_WS_MAC9 ) - return QCString(latin1()); //I'm evil.. + if ( !codec ) codec = QTextCodec::codecForMib(4); // Use ISO-8859-1 codec + return codec->fromUnicode(*this); #endif #ifdef Q_WS_WIN return qt_winQString2MB( *this ); #endif -#ifdef Q_WS_QWS - return utf8(); // ##### if there is ANY 8 bit format supported? -#endif #endif } @@ -15437,15 +15496,15 @@ if ( !local8Bit ) return QString::null; -#ifdef Q_WS_X11 - QTextCodec* codec = QTextCodec::codecForLocale(); - if ( len < 0 ) len = qstrlen(local8Bit); - return codec - ? codec->toUnicode( local8Bit, len ) - : fromLatin1( local8Bit, len ); +#if defined( Q_WS_X11 ) || defined( Q_WS_MAC ) || defined( Q_WS_QWS ) +#if defined( Q_WS_MAC ) || defined( Q_WS_QWS ) + static QTextCodec *codec = QTextCodec::codecForMib(106); // Use UTF8 codec +#else + static QTextCodec* codec = QTextCodec::codecForLocale(); #endif -#if defined( Q_WS_MAC ) - return fromUtf8(local8Bit,len); + if ( len < 0 ) len = qstrlen(local8Bit); + if ( !codec ) codec = QTextCodec::codecForMib(4); // Use ISO-8859-1 codec + return codec->toUnicode( local8Bit, len ); #endif // Should this be OS_WIN32? #ifdef Q_WS_WIN @@ -15455,9 +15514,6 @@ } return qt_winMB2QString( local8Bit ); #endif -#ifdef Q_WS_QWS - return fromUtf8(local8Bit,len); -#endif #endif // QT_NO_TEXTCODEC } @@ -15659,10 +15715,17 @@ if ( len == 0 ) { // won't make a null string *this = QString::fromLatin1( "" ); } else { +#ifdef QT_NO_TEXTCODEC setUnicode( 0, len ); // resize but not copy QChar *p = d->unicode; while ( len-- ) *p++ = *str++; +#else + QString tmp( QString::fromLocal8Bit( str ) ); + tmp.d->ref(); + deref(); + d = tmp.d; +#endif // QT_NO_TEXTCODEC } return *this; } @@ -15845,22 +15908,7 @@ bool operator==( const QString &s1, const char *s2 ) -{ - if ( !s2 ) - return s1.isNull(); - - int len = s1.length(); - const QChar *uc = s1.unicode(); - while( len ) { - if ( !(*s2) || uc->unicode() != *s2 ) { - break; - } - ++uc; - ++s2; - --len; - } - return (len ? FALSE : (*s2) ? FALSE : TRUE); -} +{ return (s1 == QString::fromLocal8Bit(s2)); } bool operator==( const char *s1, const QString &s2 ) { return (s2 == s1 ); } @@ -15872,28 +15920,28 @@ { return !(s1==s2); } bool operator<( const QString &s1, const char *s2 ) -{ return ucstrcmp(s1,s2) < 0; } +{ return ucstrcmp(s1,QString::fromLocal8Bit(s2)) < 0; } bool operator<( const char *s1, const QString &s2 ) -{ return ucstrcmp(s1,s2) < 0; } +{ return ucstrcmp(QString::fromLocal8Bit(s1),s2) < 0; } bool operator<=( const QString &s1, const char *s2 ) -{ return ucstrcmp(s1,s2) <= 0; } +{ return ucstrcmp(s1,QString::fromLocal8Bit(s2)) <= 0; } bool operator<=( const char *s1, const QString &s2 ) -{ return ucstrcmp(s1,s2) <= 0; } +{ return ucstrcmp(QString::fromLocal8Bit(s1),s2) <= 0; } bool operator>( const QString &s1, const char *s2 ) -{ return ucstrcmp(s1,s2) > 0; } +{ return ucstrcmp(s1,QString::fromLocal8Bit(s2)) > 0; } bool operator>( const char *s1, const QString &s2 ) -{ return ucstrcmp(s1,s2) > 0; } +{ return ucstrcmp(QString::fromLocal8Bit(s1),s2) > 0; } bool operator>=( const QString &s1, const char *s2 ) -{ return ucstrcmp(s1,s2) >= 0; } +{ return ucstrcmp(s1,QString::fromLocal8Bit(s2)) >= 0; } bool operator>=( const char *s1, const QString &s2 ) -{ return ucstrcmp(s1,s2) >= 0; } +{ return ucstrcmp(QString::fromLocal8Bit(s1),s2) >= 0; } /***************************************************************************** @@ -16108,7 +16156,7 @@ QDataStream &operator<<( QDataStream &s, const QString &str ) { if ( s.version() == 1 ) { - QCString l( str.latin1() ); + QCString l( str.local8Bit() ); s << l; } else { @@ -16163,7 +16211,7 @@ if ( s.version() == 1 ) { QCString l; s >> l; - str = QString( l ); + str = QString::fromLocal8Bit( l ); } else { Q_UINT32 bytes; diff -Naur qt-x11-free-3.0.2.orig/src/tools/qstring.h qt-x11-free-3.0.2/src/tools/qstring.h --- qt-x11-free-3.0.2.orig/src/tools/qstring.h Mon Feb 18 15:46:57 2002 +++ qt-x11-free-3.0.2/src/tools/qstring.h Tue Mar 12 20:18:00 2002 @@ -173,7 +173,7 @@ Decomposition decompositionTag() const; unsigned char combiningClass() const; - char latin1() const { return ucs > 0xff ? 0 : (char) ucs; } + char latin1() const; ushort unicode() const { return ucs; } ushort &unicode() { return ucs; } #ifndef QT_NO_CAST_ASCII @@ -225,20 +225,6 @@ grp = 0; #endif } -inline QChar::QChar( char c ) -{ - ucs = (uchar)c; -#ifdef QT_QSTRING_UCS_4 - grp = 0; -#endif -} -inline QChar::QChar( uchar c ) -{ - ucs = c; -#ifdef QT_QSTRING_UCS_4 - grp = 0; -#endif -} inline QChar::QChar( uchar c, uchar r ) { ucs = (r << 8) | c; @@ -286,12 +272,12 @@ inline bool operator==( char ch, QChar c ) { - return ((uchar) ch) == c.ucs; + return QChar((uchar) ch).ucs == c.ucs; } inline bool operator==( QChar c, char ch ) { - return ((uchar) ch) == c.ucs; + return QChar((uchar) ch).ucs == c.ucs; } inline bool operator==( QChar c1, QChar c2 ) @@ -306,22 +292,22 @@ inline bool operator!=( char ch, QChar c ) { - return ((uchar)ch) != c.ucs; + return QChar((uchar) ch).ucs != c.ucs; } inline bool operator!=( QChar c, char ch ) { - return ((uchar) ch) != c.ucs; + return QChar((uchar) ch).ucs != c.ucs; } inline bool operator<=( QChar c, char ch ) { - return c.ucs <= ((uchar) ch); + return c.ucs <= QChar((uchar) ch).ucs; } inline bool operator<=( char ch, QChar c ) { - return ((uchar) ch) <= c.ucs; + return QChar((uchar) ch).ucs <= c.ucs; } inline bool operator<=( QChar c1, QChar c2 ) @@ -718,7 +704,7 @@ // inline QString::~QString() { - if ( d->deref() ) { + if ( d && d->deref() ) { if ( d == shared_null ) shared_null = 0; d->deleteSelf();