* [kde-russian] Патчи для qt3. Проблемы с преобразованием
@ 2002-03-15 10:00 Сукиязов Сергей Александрович
0 siblings, 0 replies; only message in thread
From: Сукиязов Сергей Александрович @ 2002-03-15 10:00 UTC (permalink / raw)
To: kde-russian
[-- Attachment #1: Type: text/plain, Size: 2980 bytes --]
Привет
Я сделал патчи которые меняют поведение класса QString при преобразовании
из char * <--> QString. Проблемы возникают когда используется преобразование
по умолчанию, т.е. конструктор QString(const char *) и т.п. О всех нюансах я
писал в своей статье "Использование Qt-2.2.x в русскоязычных программах "
(http://www.kde.ru/docs.php?action=show&id=qt_russian). К сожалению избежать
бинарной несовмесимости не удалось :((( Несовместимость возникает из-за того
что некоторые изменяемые методы реализованны как inline.
Сейчас Тролли согласились рассмотреть эти замечания, и я надеюсь поведение
конструкторов QString всё-таки изменится (наверное в версии 3.1 или 4.0).
Если у кого есть желание и время потестируйте эти патчи. Я договорился
с Троллями что на следующей неделе (где-то во вторник - среду) отправлю
им патчи. Так что, если у кого есть какие-нибудь замечания или дополнения
я жду :)))))
Патчи накладываются в порядке указанном как 'step.x'.
Краткое описание:
qt-x11-free-3.0.2-0004-step.0.diff
----------------------------------------------
Этот патч убирает зависимость между классами QTextCodec и конструкторами
QString изпользуемыми для преобазования char * <--> QString. В противном
случае, т.к. мы в конструкторах будем использовать QTextCodec, будут
возникать "мертвые циклы" (death loops) [Конструктор QString] -> [Метод
QTextCodec] -> [Конструктор QString] -> ....
qt-x11-free-3.0.2-0004-step.1.diff
----------------------------------------------
Этот патч приводит в соответствие поведение метода QTextCodec::toUnicode в
соответствие с поведением конструкторов QString отвечающих за преобразование
char * <--> QString. Дело в том что оригинальное поведение выглядит след.
образом:
- QString str(0) или QString str - создают строку str для которой выполняют-
ся условия: str.isNull() == TRUE и str.isEmpty() == TRUE.
- str = QTextCodec::toUnicode(0,...) - создают строку str для которой выпол-
няются условия: str.isNull() == TRUE и str.isEmpty() == TRUE.
В этой части поведение совпадает.
- QString str("") - создают строку str для которой выполняются условия:
str.isNull() == FALSE и str.isEmpty() == TRUE.
- str = QTextCodec::toUnicode("",...) - создают строку str для которой выпол-
няются условия: str.isNull() == TRUE и str.isEmpty() == TRUE.
В этой части поведение не совпадает.
qt-x11-free-3.0.2-0004-step.2.diff
----------------------------------------------
Этот патч изменяет поведение конструкторов класса QString. После применения
этого патча преобразование char * <--> QString выполняется с помощью колека
для установок локали.
qt-x11-free-3.0.2-0004-step.3.diff
----------------------------------------------
Этот патч испавляет все остальные методы и конструкторы, в т.ч. и для класса
QChar. Этот патч вносит бинарную несовместимость, из-за того что некоторые
методы сделаны как inline.
--
С Уважением
Сукиязов Сергей
[-- Attachment #2: qt-x11-free-3.0.2-0004-step.3.diff --]
[-- Type: text/x-diff, Size: 11367 bytes --]
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();
[-- Attachment #3: qt-x11-free-3.0.2-0004-step.2.diff --]
[-- Type: text/x-diff, Size: 1420 bytes --]
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 Sun Mar 3 14:52:32 2002
+++ qt-x11-free-3.0.2/src/tools/qstring.cpp Sun Mar 3 14:52:32 2002
@@ -12603,9 +12603,9 @@
\sa isNull()
*/
-QString::QString( int size, bool /*dummy*/ )
+QString::QString( int size, bool make_blank )
{
- if ( size ) {
+ if ( size || ( !size && make_blank ) ) {
Q2HELPER(stat_construct_int++)
int l = size;
Q2HELPER(stat_construct_int_size+=l)
@@ -12626,9 +12626,14 @@
QString::QString( const QByteArray& ba )
{
Q2HELPER(stat_construct_ba++)
- uint l;
- QChar *uc = internalAsciiToUnicode(ba,&l);
- d = new QStringData(uc,l,l);
+ if(ba.isNull()) {
+ QString tmp = ba.size() ? QString::fromLocal8Bit(ba.data()) : QString(0,true);
+ tmp.d->ref();
+ d = tmp.d;
+ } else {
+ d = shared_null ? shared_null : makeSharedNull();
+ d->ref();
+ }
}
/*!
@@ -12679,10 +12684,14 @@
QString::QString( const char *str )
{
Q2HELPER(stat_construct_charstar++)
- uint l;
- QChar *uc = internalAsciiToUnicode(str,&l);
- Q2HELPER(stat_construct_charstar_size+=l)
- d = new QStringData(uc,l,l);
+ if(str) {
+ QString tmp = str[0] ? QString::fromLocal8Bit(str) : QString(0,true);
+ tmp.d->ref();
+ d = tmp.d;
+ } else {
+ d = shared_null ? shared_null : makeSharedNull();
+ d->ref();
+ }
}
[-- Attachment #4: qt-x11-free-3.0.2-0004-step.1.diff --]
[-- Type: text/x-diff, Size: 28228 bytes --]
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<len; i++) {
- uchar ch = chars[i];
- if ( ch < 0x80 ) {
- // ASCII
- result += QChar(ch);
- } else if ( IsBig5Char(ch) ) {
- // Big5 1984
- if ( i < len-1 ) {
- uchar c2 = chars[++i];
- if ( (c2 >=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<len; i++) {
+ uchar ch = chars[i];
+ if ( ch < 0x80 ) {
+ // ASCII
+ result += QAsciiChar(ch);
+ } else if ( IsBig5Char(ch) ) {
+ // Big5 1984
+ if ( i < len-1 ) {
+ uchar c2 = chars[++i];
+ if ( (c2 >=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; i<len; i++) {
- uchar ch = chars[i];
- if ( ch < 0x80 ) {
- // ASCII
- result += QChar(ch);
- } else if ( ch == Ss2 ) {
- // JIS X 0201 Kana
- if ( i < len-1 ) {
- uchar c2 = chars[++i];
- if ( IsKana(c2) ) {
- uint u = conv->jisx0201ToUnicode(c2);
- result += QValidChar(u);
- } else {
- i--;
- result += QChar::replacement;
+ 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 ( ch == Ss2 ) {
+ // JIS X 0201 Kana
+ if ( i < len-1 ) {
+ uchar c2 = chars[++i];
+ if ( IsKana(c2) ) {
+ uint u = conv->jisx0201ToUnicode(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<len; i++) {
- uchar ch = chars[i];
- if (ch == 0)
- break;
- if ( ch < 0x80 ) {
- // ASCII
- result += QChar(ch);
- } else if ( IsEucChar(ch) ) {
- // KSC 5601
- if ( i < len-1 ) {
- uchar c2 = chars[++i];
- if ( IsEucChar(c2) ) {
- uint u = qt_Ksc5601ToUnicode((ch << 8) | c2);
- result += QValidChar(u);
+ if (chars) {
+ result.setLength(0);
+ for (int i=0; i<len; i++) {
+ uchar ch = chars[i];
+ if (ch == 0)
+ break;
+ if ( ch < 0x80 ) {
+ // ASCII
+ result += QAsciiChar(ch);
+ } else if ( IsEucChar(ch) ) {
+ // KSC 5601
+ if ( i < len-1 ) {
+ uchar c2 = chars[++i];
+ if ( IsEucChar(c2) ) {
+ uint u = qt_Ksc5601ToUnicode((ch << 8) | c2);
+ 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;
@@ -291,7 +295,7 @@
case 0:
if ( ch < 0x80 ) {
// ASCII
- result += QChar(ch);
+ result += QAsciiChar(ch);
} else if ( IsEucChar(ch) ) {
// KSC 5601
buf[0] = ch;
diff -Naur qt-x11-free-3.0.2.orig/src/codecs/qgbkcodec.cpp qt-x11-free-3.0.2/src/codecs/qgbkcodec.cpp
--- qt-x11-free-3.0.2.orig/src/codecs/qgbkcodec.cpp Mon Feb 18 15:46:29 2002
+++ qt-x11-free-3.0.2/src/codecs/qgbkcodec.cpp Tue Mar 12 12:43:22 2002
@@ -84,6 +84,7 @@
#define IsFirstByte(c) (((c) >= 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<len; i++) {
- uchar ch = chars[i];
- if ( IsLatin(ch) ) {
- // ASCII
- result += QChar(ch);
- } else if ( IsFirstByte(ch) ) {
- // GBK ?
- if ( i < len-1 ) {
- uchar c2 = chars[++i];
- if ( IsSecondByte(c2) ) {
- uint u = qt_GBKToUnicode((ch << 8) | c2);
- result += QValidChar(u);
+ if (chars) {
+ result.setLength(0);
+ for (int i=0; i<len; i++) {
+ uchar ch = chars[i];
+ if ( IsLatin(ch) ) {
+ // ASCII
+ result += QAsciiChar(ch);
+ } else if ( IsFirstByte(ch) ) {
+ // GBK ?
+ if ( i < len-1 ) {
+ uchar c2 = chars[++i];
+ if ( IsSecondByte(c2) ) {
+ uint u = qt_GBKToUnicode((ch << 8) | c2);
+ result += QValidChar(u);
+ } else {
+ i--;
+ result += QChar::replacement;
+ }
} else {
- i--;
+ //Bad String
result += QChar::replacement;
}
} else {
- //Bad String
+ // Invalid
result += QChar::replacement;
}
- } else {
- // Invalid
- result += QChar::replacement;
}
}
return result;
@@ -224,7 +228,7 @@
case 0:
if ( ch < 0x80 ) {
// ASCII
- result += QChar(ch);
+ result += QAsciiChar(ch);
} else if ( IsFirstByte(ch) ) {
// GBK ?
buf[0] = ch;
diff -Naur qt-x11-free-3.0.2.orig/src/codecs/qjiscodec.cpp qt-x11-free-3.0.2/src/codecs/qjiscodec.cpp
--- qt-x11-free-3.0.2.orig/src/codecs/qjiscodec.cpp Mon Feb 18 15:46:29 2002
+++ qt-x11-free-3.0.2/src/codecs/qjiscodec.cpp Tue Mar 12 12:46:24 2002
@@ -145,6 +145,7 @@
#define IsJisChar(c) (((c) >= 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; i<len; i++) {
- uchar ch = chars[i];
- if ( ch == Esc ) {
- // Escape sequence
- state = Unknown;
- if ( i < len-1 ) {
- uchar c2 = chars[++i];
- if (c2 == '$') {
- if ( i < len-1 ) {
- uchar c3 = chars[++i];
- if (strchr(Esc_CHARS, c3)) {
- if ( i < len-1 ) {
- uchar c4 = chars[++i];
- if (c4 == '(') {
- switch (c4) {
- case 'D':
- state = JISX0212; // Esc $ ( D
- break;
- }
- }
- }
- } else {
- switch (c3) {
- case '@':
- state = JISX0208_1978; // Esc $ @
- break;
- case 'B':
- state = JISX0208_1983; // Esc $ B
- break;
- }
- }
- }
- } else {
- if (strchr(Esc_CHARS, c2)) {
+ if (chars) {
+ result.setLength(0);
+ Iso2022State state = Ascii, prev = Ascii;
+ for (int i=0; i<len; i++) {
+ uchar ch = chars[i];
+ if ( ch == Esc ) {
+ // Escape sequence
+ state = Unknown;
+ if ( i < len-1 ) {
+ uchar c2 = chars[++i];
+ if (c2 == '$') {
if ( i < len-1 ) {
uchar c3 = chars[++i];
- if (c2 == '(') {
+ if (strchr(Esc_CHARS, c3)) {
+ if ( i < len-1 ) {
+ uchar c4 = chars[++i];
+ if (c4 == '(') {
+ switch (c4) {
+ case 'D':
+ state = JISX0212; // Esc $ ( D
+ break;
+ }
+ }
+ }
+ } else {
switch (c3) {
- case 'B':
- state = Ascii; // Esc ( B
+ case '@':
+ state = JISX0208_1978; // Esc $ @
break;
- case 'I':
- state = JISX0201_Kana; // Esc ( I
- break;
- case 'J':
- state = JISX0201_Latin; // Esc ( J
+ case 'B':
+ state = JISX0208_1983; // Esc $ B
break;
}
}
}
+ } else {
+ if (strchr(Esc_CHARS, c2)) {
+ if ( i < len-1 ) {
+ uchar c3 = chars[++i];
+ if (c2 == '(') {
+ switch (c3) {
+ case 'B':
+ state = Ascii; // Esc ( B
+ break;
+ case 'I':
+ state = JISX0201_Kana; // Esc ( I
+ break;
+ case 'J':
+ state = JISX0201_Latin; // Esc ( J
+ break;
+ }
+ }
+ }
+ }
}
}
- }
- } else if (ch == So) {
- // Shift out
- prev = state;
- state = JISX0201_Kana;
- } else if (ch == Si) {
- // Shift in
- if (prev == Ascii || prev == JISX0201_Latin) {
- state = prev;
- } else {
- state = Ascii;
- }
- } else {
- uint u;
- switch (state) {
- case Ascii:
- if (ch < 0x80) {
- result += QChar(ch);
- break;
+ } else if (ch == So) {
+ // Shift out
+ prev = state;
+ state = JISX0201_Kana;
+ } else if (ch == Si) {
+ // Shift in
+ if (prev == Ascii || prev == JISX0201_Latin) {
+ state = prev;
+ } else {
+ state = Ascii;
}
+ } else {
+ uint u;
+ switch (state) {
+ case Ascii:
+ if (ch < 0x80) {
+ result += QAsciiChar(ch);
+ break;
+ }
/* fall throught */
- case JISX0201_Latin:
- u = conv->jisx0201ToUnicode(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<len; i++ ) {
- if ( c[i] > 127 )
- r[i] = heb_to_unicode[c[i]-128];
- else
- r[i] = c[i];
- }
+ for( int i=0; i<len; i++ ) {
+ if ( c[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; i<len; i++) {
- uchar ch = chars[i];
- if ( ch < 0x80 || IsKana(ch) ) {
- // JIS X 0201 Latin or JIS X 0201 Kana
- uint u = conv->jisx0201ToUnicode(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; i<len; i++) {
+ uchar ch = chars[i];
+ if ( ch < 0x80 || IsKana(ch) ) {
+ // JIS X 0201 Latin or JIS X 0201 Kana
+ uint u = conv->jisx0201ToUnicode(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; i<len; i++) {
- uchar ch = chars[i];
- if (need) {
- if ( (ch&0xc0) == 0x80 ) {
- uc = (uc << 6) | (ch & 0x3f);
- need--;
- if ( !need ) {
- result += QChar(uc);
+ QString result;
+ if (chars) {
+ result.setLength(0);
+
+ for (int i=0; i<len; i++) {
+ uchar ch = chars[i];
+ if (need) {
+ if ( (ch&0xc0) == 0x80 ) {
+ uc = (uc << 6) | (ch & 0x3f);
+ need--;
+ if ( !need ) {
+ result += QAsciiChar(uc);
+ }
+ } else {
+ // error
+ result += QChar::replacement;
+ need = 0;
}
} else {
- // error
- result += QChar::replacement;
- need = 0;
- }
- } else {
- if ( ch < 128 ) {
- result += QChar(ch);
- } else if ( (ch&0xe0) == 0xc0 ) {
- uc = ch &0x1f;
- need = 1;
- } else if ( (ch&0xf0) == 0xe0 ) {
- uc = ch &0x0f;
- need = 2;
+ if ( ch < 128 ) {
+ result += QAsciiChar(ch);
+ } else if ( (ch&0xe0) == 0xc0 ) {
+ uc = ch &0x1f;
+ need = 1;
+ } else if ( (ch&0xf0) == 0xe0 ) {
+ uc = ch &0x0f;
+ need = 2;
+ }
}
}
}
@@ -230,35 +236,36 @@
QString toUnicode(const char* chars, int len)
{
QString r;
-
- while ( len-- ) {
- if ( half ) {
- QChar ch;
- if ( swap ) {
- ch.setRow( *chars++ );
- ch.setCell( buf );
- } else {
- ch.setRow( buf );
- ch.setCell( *chars++ );
- }
- if ( !headerdone ) {
- if ( ch == QChar::byteOrderSwapped ) {
- swap = !swap;
- } else if ( ch == QChar::byteOrderMark ) {
- // Ignore ZWNBSP
+ if (chars) {
+ r.setLength(0);
+ while ( len-- ) {
+ if ( half ) {
+ QChar ch;
+ if ( swap ) {
+ ch.setRow( *chars++ );
+ ch.setCell( buf );
} else {
- r += ch;
+ ch.setRow( buf );
+ ch.setCell( *chars++ );
}
- headerdone = TRUE;
- } else
- r += ch;
- half = FALSE;
- } else {
- buf = *chars++;
- half = TRUE;
+ if ( !headerdone ) {
+ if ( ch == QChar::byteOrderSwapped ) {
+ swap = !swap;
+ } else if ( ch == QChar::byteOrderMark ) {
+ // Ignore ZWNBSP
+ } else {
+ r += ch;
+ }
+ headerdone = TRUE;
+ } else
+ r += ch;
+ half = FALSE;
+ } else {
+ buf = *chars++;
+ half = TRUE;
+ }
}
}
-
return r;
}
};
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 Mon Feb 18 15:46:57 2002
+++ qt-x11-free-3.0.2/src/tools/qstring.cpp Tue Mar 12 19:22:34 2002
@@ -16378,6 +16378,11 @@
int len=0;
while ( ((TCHAR*)tc)[len] )
len++;
+ if ( !len ) {
+ QString r;
+ r.setlength(0);
+ return r;
+ }
# if defined(Q_WS_X11) || defined(QT_WIN32BYTESWAP)
QString r;
for ( int i=0; i<len; i++ )
@@ -16430,39 +16435,46 @@
// WATCH OUT: mblen must include the NUL (or just use -1)
QString qt_winMB2QString( const char* mb, int mblen )
{
- if ( !mb || !mblen )
- return QString::null;
- const int wclen_auto = 4096;
- WCHAR wc_auto[wclen_auto];
- int wclen = wclen_auto;
- WCHAR *wc = wc_auto;
- int len;
- while ( !(len=MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED,
+ QString result;
+ if ( mb ) {
+ result.setLength(0);
+
+ if ( !mblen ) return result;
+
+ const int wclen_auto = 4096;
+ WCHAR wc_auto[wclen_auto];
+ int wclen = wclen_auto;
+ WCHAR *wc = wc_auto;
+ int len;
+
+ while ( !(len=MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED,
mb, mblen, wc, wclen )) )
- {
- int r = GetLastError();
- if ( r == ERROR_INSUFFICIENT_BUFFER ) {
- if ( wc != wc_auto ) {
- qWarning("Size changed in MultiByteToWideChar");
- break;
+ {
+ int r = GetLastError();
+ if ( r == ERROR_INSUFFICIENT_BUFFER ) {
+ if ( wc != wc_auto ) {
+ qWarning("Size changed in MultiByteToWideChar");
+ break;
+ } else {
+ wclen = MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED,
+ mb, mblen, 0, 0 );
+ wc = new WCHAR[wclen];
+ // and try again...
+ }
} else {
- wclen = MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED,
- mb, mblen, 0, 0 );
- wc = new WCHAR[wclen];
- // and try again...
+ // Fail.
+ qWarning("MultiByteToWideChar cannot convert multibyte text");
+ break;
}
- } else {
- // Fail.
- qWarning("MultiByteToWideChar cannot convert multibyte text");
- break;
}
+
+ if ( len >0 ) {
+ 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 );
}
[-- Attachment #5: qt-x11-free-3.0.2-0004-step.0.diff --]
[-- Type: text/x-diff, Size: 4003 bytes --]
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 Mon Feb 18 15:46:29 2002
+++ qt-x11-free-3.0.2/src/codecs/qtextcodec.cpp Tue Mar 12 12:17:01 2002
@@ -424,19 +424,21 @@
// returns a string cotnaining the letters and numbers from input,
// with a space separating run of a character class. e.g. "iso8859-1"
// becomes "iso 8859 1"
-static QString lettersAndNumbers( const char * input )
+static QCString lettersAndNumbers( const char * input )
{
- QString result;
- QChar c;
+ QCString result;
+ QChar c, n;
while( input && *input ) {
- c = *input;
+ c.setCell(*input);
+ c.setRow(0);
if ( c.isLetter() || c.isNumber() )
- result += c.lower();
+ result += c.lower().cell();
if ( input[1] ) {
// add space at character class transition, except
// transition from upper-case to lower-case letter
- QChar n( input[1] );
+ n.setCell(input[1]);
+ n.setRow(0);
if ( c.isLetter() && n.isLetter() ) {
if ( c == c.lower() && n == n.upper() )
result += ' ';
@@ -464,8 +466,8 @@
// if the letters and numbers are the same, we have an "almost"
// perfect match.
- QString h( lettersAndNumbers( hint ) );
- QString n( lettersAndNumbers( name ) );
+ QCString h( lettersAndNumbers( hint ) );
+ QCString n( lettersAndNumbers( name ) );
if ( h == n )
return qstrlen( hint )-1;
@@ -1540,19 +1542,22 @@
QString QTextCodecFromIODDecoder::toUnicode(const char* chars, int len)
{
- const uchar* uchars = (const uchar*)chars;
QString result;
- while (len--) {
- QMultiByteUnicodeTable& t = mb[*uchars];
- if ( t.multibyte ) {
- // Chained multi-byte
- mb = t.multibyte;
- } else {
- if ( t.unicode )
- result += QChar(t.unicode);
- mb=codec->to_unicode_multibyte;
+ if(chars) {
+ const uchar* uchars = (const uchar*)chars;
+ result.setLength(0);
+ while (len--) {
+ QMultiByteUnicodeTable& t = mb[*uchars];
+ if ( t.multibyte ) {
+ // Chained multi-byte
+ mb = t.multibyte;
+ } else {
+ if ( t.unicode )
+ result += QChar(t.unicode);
+ mb=codec->to_unicode_multibyte;
+ }
+ uchars++;
}
- uchars++;
}
return result;
}
@@ -2262,26 +2267,30 @@
QString QSimpleTextCodec::toUnicode(const char* chars, int len) const
{
- if ( len <= 0 || chars == 0 )
- return QString::null;
-
- const unsigned char * c = (const unsigned char *)chars;
- int i;
-
- for ( i = 0; i < len; i++ ) {
- if ( c[i] == '\0' )
- len = i;
- }
-
QString r;
- r.setUnicode(0, len);
- QChar* uc = (QChar*)r.unicode(); // const_cast
- for ( i = 0; i < len; i++ ) {
- if ( c[i] > 127 )
- uc[i] = unicodevalues[forwardIndex].values[c[i]-128];
- else
- uc[i] = c[i];
+ if (chars) {
+ 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 {
+ r.setUnicode(0, len);
+ QChar* uc = (QChar*)r.unicode(); // const_cast
+
+ for ( i = 0; i < len; i++ ) {
+ if ( c[i] > 127 )
+ uc[i] = unicodevalues[forwardIndex].values[c[i]-128];
+ else {
+ uc[i].setCell( c[i] );
+ uc[i].setRow(0);
+ }
+ }
+ }
}
return r;
}
@@ -2448,10 +2457,28 @@
QString QLatin1Codec::toUnicode(const char* chars, int len) const
{
- if(len <= 0)
- return QString::null;
+ QString r;
- return QString::fromLatin1(chars, len);
+ if (chars) {
+ 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 {
+ r.setUnicode(0, len);
+ QChar* uc = (QChar*)r.unicode(); // const_cast
+
+ for ( i = 0; i < len; i++ ) {
+ uc[i].setCell( c[i] );
+ uc[i].setRow(0);
+ }
+ }
+ }
+ return r;
}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2002-03-15 10:00 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-03-15 10:00 [kde-russian] Патчи для qt3. Проблемы с преобразованием Сукиязов Сергей Александрович
рассылка русскоязычной группы пользователей и разработчиков KDE
This inbox may be cloned and mirrored by anyone:
git clone --mirror http://lore.altlinux.org/kde-russian/0 kde-russian/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 kde-russian kde-russian/ http://lore.altlinux.org/kde-russian \
kde-russian@lists.kde.ru
public-inbox-index kde-russian
Example config snippet for mirrors.
Newsgroup available over NNTP:
nntp://lore.altlinux.org/org.altlinux.lists.kde-russian
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git