diff -Naur qt-x11-free-3.0.2.orig/src/codecs/qbig5codec.cpp qt-x11-free-3.0.2/src/codecs/qbig5codec.cpp --- qt-x11-free-3.0.2.orig/src/codecs/qbig5codec.cpp Mon Feb 18 15:46:28 2002 +++ qt-x11-free-3.0.2/src/codecs/qbig5codec.cpp Tue Mar 12 12:37:41 2002 @@ -52,6 +52,7 @@ #define IsBig5Char(c) (((c) >= 0x81) && ((c) <= 0xfe)) #define QValidChar(u) ((u) ? QChar((ushort)(u)) : QChar::replacement) +#define QAsciiChar(u) (QChar((ushort)(u))) int QBig5Codec::mibEnum() const @@ -88,32 +89,35 @@ QString QBig5Codec::toUnicode(const char* chars, int len) const { - QString result; - for (int i=0; i=0x40) && (c2 <=0xfe) ) { - uint u = qt_Big5ToUnicode((ch << 8) | c2); - result += QValidChar(u); - } else { - i--; - result += QChar::replacement; + QString result; + if (chars) { + result.setLength(0); + for (int i=0; i=0x40) && (c2 <=0xfe) ) { + uint u = qt_Big5ToUnicode((ch << 8) | c2); + result += QValidChar(u); + } else { + i--; + result += QChar::replacement; + } + } else { + result += QChar::replacement; + } + } else { + // Invalid + result += QChar::replacement; + } } - } else { - result += QChar::replacement; - } - } else { - // Invalid - result += QChar::replacement; } - } - return result; + return result; } const char* QBig5Codec::name() const @@ -197,7 +201,7 @@ case 0: if ( ch < 0x80 ) { // ASCII - result += QChar(ch); + result += QAsciiChar(ch); } else if ( IsBig5Char(ch) ) { // Big5 1984 buf[0] = ch; diff -Naur qt-x11-free-3.0.2.orig/src/codecs/qeucjpcodec.cpp qt-x11-free-3.0.2/src/codecs/qeucjpcodec.cpp --- qt-x11-free-3.0.2.orig/src/codecs/qeucjpcodec.cpp Mon Feb 18 15:46:28 2002 +++ qt-x11-free-3.0.2/src/codecs/qeucjpcodec.cpp Tue Mar 12 12:39:50 2002 @@ -124,6 +124,7 @@ #define IsEucChar(c) (((c) >= 0xa1) && ((c) <= 0xfe)) #define QValidChar(u) ((u) ? QChar((ushort)(u)) : QChar::replacement) +#define QAsciiChar(u) (QChar((ushort)(u))) /*! Constructs a QEucJpCodec. @@ -214,64 +215,67 @@ QString QEucJpCodec::toUnicode(const char* chars, int len) const { QString result; - for (int i=0; ijisx0201ToUnicode(c2); - result += QValidChar(u); - } else { - i--; - result += QChar::replacement; + if (chars) { + result.setLength(0); + for (int i=0; ijisx0201ToUnicode(c2); + result += QValidChar(u); + } else { + i--; + result += QChar::replacement; + } } - } - } else if ( ch == Ss3 ) { - // JIS X 0212 - if ( i < len-1 ) { - uchar c2 = chars[++i]; - if ( IsEucChar(c2) ) { - if ( i < len-1 ) { - uchar c3 = chars[++i]; - if ( IsEucChar(c3) ) { - uint u = conv->jisx0212ToUnicode(c2 & 0x7f, c3 & 0x7f); - result += QValidChar(u); + } else if ( ch == Ss3 ) { + // JIS X 0212 + if ( i < len-1 ) { + uchar c2 = chars[++i]; + if ( IsEucChar(c2) ) { + if ( i < len-1 ) { + uchar c3 = chars[++i]; + if ( IsEucChar(c3) ) { + uint u = conv->jisx0212ToUnicode(c2 & 0x7f, c3 & 0x7f); + result += QValidChar(u); + } else { + i--; + result += QChar::replacement; + } } else { - i--; result += QChar::replacement; } } else { + i--; result += QChar::replacement; } } else { - i--; result += QChar::replacement; } - } else { - result += QChar::replacement; - } - } else if ( IsEucChar(ch) ) { - // JIS X 0208 - if ( i < len-1 ) { - uchar c2 = chars[++i]; - if ( IsEucChar(c2) ) { - uint u = conv->jisx0208ToUnicode(ch & 0x7f, c2 & 0x7f); - result += QValidChar(u); + } else if ( IsEucChar(ch) ) { + // JIS X 0208 + if ( i < len-1 ) { + uchar c2 = chars[++i]; + if ( IsEucChar(c2) ) { + uint u = conv->jisx0208ToUnicode(ch & 0x7f, c2 & 0x7f); + result += QValidChar(u); + } else { + i--; + result += QChar::replacement; + } } else { - i--; result += QChar::replacement; } } else { + // Invalid result += QChar::replacement; } - } else { - // Invalid - result += QChar::replacement; } } return result; @@ -411,7 +415,7 @@ case 0: if ( ch < 0x80 ) { // ASCII - result += QChar(ch); + result += QAsciiChar(ch); } else if ( ch == Ss2 || ch == Ss3 ) { // JIS X 0201 Kana or JIS X 0212 buf[0] = ch; diff -Naur qt-x11-free-3.0.2.orig/src/codecs/qeuckrcodec.cpp qt-x11-free-3.0.2/src/codecs/qeuckrcodec.cpp --- qt-x11-free-3.0.2.orig/src/codecs/qeuckrcodec.cpp Mon Feb 18 15:46:28 2002 +++ qt-x11-free-3.0.2/src/codecs/qeuckrcodec.cpp Tue Mar 12 12:41:25 2002 @@ -98,6 +98,7 @@ #define IsEucChar(c) (((c) >= 0xa1) && ((c) <= 0xfe)) #define QValidChar(u) ((u) ? QChar((ushort)(u)) : QChar::replacement) +#define QAsciiChar(u) (QChar((ushort)(u))) /*! \reimp @@ -154,30 +155,33 @@ QString QEucKrCodec::toUnicode(const char* chars, int len) const { QString result; - for (int i=0; i= 0x81) && ((c) <= 0xFE)) #define IsSecondByte(c) ((((c) >= 0x40) && ((c) <= 0x7E)) || ((((c) >= 0x80) && ((c) <= 0xFE)))) #define QValidChar(u) ((u) ? QChar((ushort)(u)) : QChar::replacement) +#define QAsciiChar(u) (QChar((ushort)(u))) static unsigned int qt_GBKToUnicode(unsigned int code); unsigned int qt_UnicodeToGBK(unsigned int unicode); @@ -130,29 +131,32 @@ QString QGbkCodec::toUnicode(const char* chars, int len) const { QString result; - for (int i=0; i= 0x21) && ((c) <= 0x7e)) #define QValidChar(u) ((u) ? QChar((ushort)(u)) : QChar::replacement) +#define QAsciiChar(u) (QChar((ushort)(u))) enum Iso2022State{ Ascii, MinState = Ascii, JISX0201_Latin, JISX0201_Kana, @@ -260,106 +261,109 @@ QString QJisCodec::toUnicode(const char* chars, int len) const { QString result; - Iso2022State state = Ascii, prev = Ascii; - for (int i=0; ijisx0201ToUnicode(ch); - result += QValidChar(u); - break; - case JISX0201_Kana: - u = conv->jisx0201ToUnicode(ch | 0x80); - result += QValidChar(u); - break; - case JISX0208_1978: - case JISX0208_1983: - if ( i < len-1 ) { - uchar c2 = chars[++i]; - u = conv->jisx0208ToUnicode(ch & 0x7f, c2 & 0x7f); + case JISX0201_Latin: + u = conv->jisx0201ToUnicode(ch); result += QValidChar(u); - } - break; - case JISX0212: - if ( i < len-1 ) { - uchar c2 = chars[++i]; - u = conv->jisx0212ToUnicode(ch & 0x7f, c2 & 0x7f); + break; + case JISX0201_Kana: + u = conv->jisx0201ToUnicode(ch | 0x80); result += QValidChar(u); + break; + case JISX0208_1978: + case JISX0208_1983: + if ( i < len-1 ) { + uchar c2 = chars[++i]; + u = conv->jisx0208ToUnicode(ch & 0x7f, c2 & 0x7f); + result += QValidChar(u); + } + break; + case JISX0212: + if ( i < len-1 ) { + uchar c2 = chars[++i]; + u = conv->jisx0212ToUnicode(ch & 0x7f, c2 & 0x7f); + result += QValidChar(u); + } + break; + default: + result += QChar::replacement; + break; } - break; - default: - result += QChar::replacement; - break; } } } @@ -646,7 +650,7 @@ switch (state) { case Ascii: if (ch < 0x80) { - result += QChar(ch); + result += QAsciiChar(ch); break; } /* fall throught */ diff -Naur qt-x11-free-3.0.2.orig/src/codecs/qrtlcodec.cpp qt-x11-free-3.0.2/src/codecs/qrtlcodec.cpp --- qt-x11-free-3.0.2.orig/src/codecs/qrtlcodec.cpp Mon Feb 18 15:46:29 2002 +++ qt-x11-free-3.0.2/src/codecs/qrtlcodec.cpp Tue Mar 12 18:58:14 2002 @@ -40,6 +40,8 @@ #ifndef QT_NO_CODEC_HEBREW +#define QAsciiChar(u) (QChar((ushort)(u))) + // NOT REVISED static const uchar unkn = '?'; // BLACK SQUARE (94) would be better @@ -302,7 +304,7 @@ // directionality, we know the answer. pos = 0; while (pos < len) { - if ( str.at(pos) == '\n' ) + if ( str.at(pos) == QAsciiChar('\n') ) startLine = pos; if (str.at(pos).direction() < 2) { // DirR or DirL dir1 = str.at(pos).direction(); @@ -315,7 +317,7 @@ return QChar::DirL; // move to end of line - while( pos < len && str.at(pos) != '\n' ) + while( pos < len && str.at(pos) != QAsciiChar('\n') ) pos++; while (pos > startLine) { @@ -336,7 +338,7 @@ pos = 0; while (pos < len-1 ) { if(str.at(pos).category() == QChar::Punctuation_Other) { - if( str.at(pos) != (char)0xbf && str.at(pos) != (char)0xa1 ) // spanish inverted question and exclamation mark + if( str.at(pos) != QAsciiChar(0xbf) && str.at(pos) != QAsciiChar(0xa1) ) // spanish inverted question and exclamation mark if( str.at(pos+1).direction() < 2 ) return QChar::DirR; } pos++; @@ -430,37 +432,43 @@ QString QHebrewCodec::toUnicode(const char* chars, int len ) const { QString r; - const unsigned char * c = (const unsigned char *)chars; - QChar::Direction basicDir = QChar::DirON; // neutral, we don't know + if (chars) { + r.setLength(0); - if( len == 0 ) return QString::null; + const unsigned char * c = (const unsigned char *)chars; + QChar::Direction basicDir = QChar::DirON; // neutral, we don't know - // Test, if the user gives us a directionality. - // We use 0xFE and 0xFF in ISO8859-8 for that. - // These chars are undefined in the charset, and are mapped to - // RTL overwrite - if( c[0] == 0xfe ) { - basicDir = QChar::DirL; - c++; // skip directionality hint - } - if( c[0] == 0xff ) { - basicDir = QChar::DirR; - c++; // skip directionality hint - } + // Won't null string if chars!=NULL + if( len != 0 ) { + // Test, if the user gives us a directionality. + // We use 0xFE and 0xFF in ISO8859-8 for that. + // These chars are undefined in the charset, and are mapped to + // RTL overwrite + if( c[0] == 0xfe ) { + basicDir = QChar::DirL; + c++; // skip directionality hint + len--; + } + if( c[0] == 0xff ) { + basicDir = QChar::DirR; + c++; // skip directionality hint + len--; + } - for( int i=0; i 127 ) - r[i] = heb_to_unicode[c[i]-128]; - else - r[i] = c[i]; - } + for( int i=0; i 127 ) + r[i] = heb_to_unicode[c[i]-128]; + else + r[i] = QAsciiChar(c[i]); + } - // do transformation from visual byte ordering to logical byte - // ordering - if( basicDir == QChar::DirON ) - basicDir = findBasicDirection(r); + // do transformation from visual byte ordering to logical byte + // ordering + if( basicDir == QChar::DirON ) + basicDir = findBasicDirection(r); - return QComplexText::bidiReorderString(r); + return QComplexText::bidiReorderString(r); + } #if 0 QString out; @@ -476,6 +484,8 @@ } return out; #endif + } + return r; } /*! diff -Naur qt-x11-free-3.0.2.orig/src/codecs/qsjiscodec.cpp qt-x11-free-3.0.2/src/codecs/qsjiscodec.cpp --- qt-x11-free-3.0.2.orig/src/codecs/qsjiscodec.cpp Mon Feb 18 15:46:29 2002 +++ qt-x11-free-3.0.2/src/codecs/qsjiscodec.cpp Tue Mar 12 19:01:00 2002 @@ -176,32 +176,35 @@ QString QSjisCodec::toUnicode(const char* chars, int len) const { QString result; - for (int i=0; ijisx0201ToUnicode(ch); - result += QValidChar(u); - } else if ( IsSjisChar1(ch) ) { - // JIS X 0208 - if ( i < len-1 ) { - uchar c2 = chars[++i]; - if ( IsSjisChar2(c2) ) { - if ( IsUserDefinedChar1(ch) ) { - result += QChar::replacement; + if (chars) { + result.setLength(0); + for (int i=0; ijisx0201ToUnicode(ch); + result += QValidChar(u); + } else if ( IsSjisChar1(ch) ) { + // JIS X 0208 + if ( i < len-1 ) { + uchar c2 = chars[++i]; + if ( IsSjisChar2(c2) ) { + if ( IsUserDefinedChar1(ch) ) { + result += QChar::replacement; + } else { + uint u = conv->sjisToUnicode(ch, c2); + result += QValidChar(u); + } } else { - uint u = conv->sjisToUnicode(ch, c2); - result += QValidChar(u); + i--; + result += QChar::replacement; } } else { - i--; result += QChar::replacement; } } else { result += QChar::replacement; } - } else { - result += QChar::replacement; } } return result; diff -Naur qt-x11-free-3.0.2.orig/src/codecs/qtextcodec.cpp qt-x11-free-3.0.2/src/codecs/qtextcodec.cpp --- qt-x11-free-3.0.2.orig/src/codecs/qtextcodec.cpp Tue Mar 12 12:34:27 2002 +++ qt-x11-free-3.0.2/src/codecs/qtextcodec.cpp Tue Mar 12 19:12:04 2002 @@ -1544,8 +1544,10 @@ { QString result; if(chars) { - const uchar* uchars = (const uchar*)chars; result.setLength(0); + + const uchar* uchars = (const uchar*)chars; + while (len--) { QMultiByteUnicodeTable& t = mb[*uchars]; if ( t.multibyte ) { @@ -2270,15 +2272,15 @@ QString r; if (chars) { + r.setLength(0); + const unsigned char * c = (const unsigned char *)chars; int i; for ( i = 0; i < len; i++ ) if ( c[i] == '\0' ) len = i; - if( len<=0 ) - r.setLength(0); - else { + if( len > 0 ) { r.setUnicode(0, len); QChar* uc = (QChar*)r.unicode(); // const_cast @@ -2460,15 +2462,15 @@ QString r; if (chars) { + r.setLength(0); + const unsigned char * c = (const unsigned char *)chars; int i; for ( i = 0; i < len; i++ ) if ( c[i] == '\0' ) len = i; - if( len<=0 ) - r.setLength(0); - else { + if( len > 0 ) { r.setUnicode(0, len); QChar* uc = (QChar*)r.unicode(); // const_cast diff -Naur qt-x11-free-3.0.2.orig/src/codecs/qtsciicodec.cpp qt-x11-free-3.0.2/src/codecs/qtsciicodec.cpp --- qt-x11-free-3.0.2.orig/src/codecs/qtsciicodec.cpp Mon Feb 18 15:46:30 2002 +++ qt-x11-free-3.0.2/src/codecs/qtsciicodec.cpp Tue Mar 12 19:08:24 2002 @@ -88,6 +88,7 @@ #define IsTSCIIChar(c) (((c) >= 0x80) && ((c) <= 0xfd)) #define QValidChar(u) ((u) ? QChar((u)) : QChar::replacement) +#define QAsciiChar(u) (QChar((ushort)(u))) /*! \reimp */ int QTsciiCodec::mibEnum() const @@ -133,26 +134,28 @@ QString QTsciiCodec::toUnicode(const char* chars, int len) const { QString result; - for (int i = 0; i < len; i++) { - uchar ch = chars[i]; - if ( ch < 0x80 ) { - // ASCII - result += QChar(ch); - } else if ( IsTSCIIChar(ch) ) { - // TSCII - uint s[3]; - uint u = qt_TSCIIToUnicode(ch, s); - uint *p = s; - while ( u-- ) { - uint c = *p++; - result += QValidChar(c); + if (chars) { + result.setLength(0); + for (int i = 0; i < len; i++) { + uchar ch = chars[i]; + if ( ch < 0x80 ) { + // ASCII + result += QAsciiChar(ch); + } else if ( IsTSCIIChar(ch) ) { + // TSCII + uint s[3]; + uint u = qt_TSCIIToUnicode(ch, s); + uint *p = s; + while ( u-- ) { + uint c = *p++; + result += QValidChar(c); + } + } else { + // Invalid + result += QChar::replacement; } - } else { - // Invalid - result += QChar::replacement; } } - return result; } diff -Naur qt-x11-free-3.0.2.orig/src/codecs/qutfcodec.cpp qt-x11-free-3.0.2/src/codecs/qutfcodec.cpp --- qt-x11-free-3.0.2.orig/src/codecs/qutfcodec.cpp Mon Feb 18 15:46:30 2002 +++ qt-x11-free-3.0.2/src/codecs/qutfcodec.cpp Tue Mar 12 19:06:47 2002 @@ -37,6 +37,8 @@ #include "qutfcodec.h" +#define QAsciiChar(u) (QChar((ushort)(u))) + #ifndef QT_NO_TEXTCODEC int QUtf8Codec::mibEnum() const @@ -127,30 +129,34 @@ QString toUnicode(const char* chars, int len) { - QString result = ""; - for (int i=0; i0 ) { + result.setUnicode( (QChar*)wc, len - 1 ); // len - 1: we don't want terminator + if ( wc != wc_auto ) + delete [] wc; + } } - if ( len <= 0 ) - return QString::null; - QString s( (QChar*)wc, len - 1 ); // len - 1: we don't want terminator - if ( wc != wc_auto ) - delete [] wc; - return s; + return result; } #endif // Q_OS_WIN32 diff -Naur qt-x11-free-3.0.2.orig/tools/linguist/shared/metatranslator.cpp qt-x11-free-3.0.2/tools/linguist/shared/metatranslator.cpp --- qt-x11-free-3.0.2.orig/tools/linguist/shared/metatranslator.cpp Tue Feb 12 19:02:53 2002 +++ qt-x11-free-3.0.2/tools/linguist/shared/metatranslator.cpp Tue Mar 12 18:43:11 2002 @@ -523,9 +523,16 @@ { if ( utf8 ) return QString::fromUtf8( str ); - else if ( codec == 0 ) - return QString( str ); - else + else if ( codec == 0 ) { + QString r; + if (str) { + if ( !str[0] ) + r.setLength(0); + else + r = QString( str ); + } + return r; + } else return codec->toUnicode( str ); }