openbsd-ports/x11/qt3/patches/patch-src_codecs_qutfcodec_cpp
espie a30e3ddd6c regen patches.
handle utf8 encoding better.
2007-03-31 22:49:46 +00:00

62 lines
1.9 KiB
Plaintext

$OpenBSD: patch-src_codecs_qutfcodec_cpp,v 1.1 2007/03/31 22:49:46 espie Exp $
--- src/codecs/qutfcodec.cpp.orig Thu Oct 19 16:25:07 2006
+++ src/codecs/qutfcodec.cpp Sat Mar 31 14:51:50 2007
@@ -154,6 +154,7 @@ int QUtf8Codec::heuristicContentMatch(const char* char
class QUtf8Decoder : public QTextDecoder {
uint uc;
+ uint min_uc;
int need;
bool headerDone;
public:
@@ -167,8 +168,9 @@ class QUtf8Decoder : public QTextDecoder { (public)
result.setLength( len ); // worst case
QChar *qch = (QChar *)result.unicode();
uchar ch;
+ int error = -1;
for (int i=0; i<len; i++) {
- ch = *chars++;
+ ch = chars[i];
if (need) {
if ( (ch&0xc0) == 0x80 ) {
uc = (uc << 6) | (ch & 0x3f);
@@ -182,6 +184,8 @@ class QUtf8Decoder : public QTextDecoder { (public)
*qch++ = QChar(high);
*qch++ = QChar(low);
headerDone = TRUE;
+ } else if ((uc < min_uc) || (uc >= 0xd800 && uc <= 0xdfff) || (uc >= 0xfffe)) {
+ *qch++ = QChar::replacement;
} else {
if (headerDone || QChar(uc) != QChar::byteOrderMark)
*qch++ = uc;
@@ -190,6 +194,7 @@ class QUtf8Decoder : public QTextDecoder { (public)
}
} else {
// error
+ i = error;
*qch++ = QChar::replacement;
need = 0;
}
@@ -200,12 +205,21 @@ class QUtf8Decoder : public QTextDecoder { (public)
} else if ((ch & 0xe0) == 0xc0) {
uc = ch & 0x1f;
need = 1;
+ error = i;
+ min_uc = 0x80;
} else if ((ch & 0xf0) == 0xe0) {
uc = ch & 0x0f;
need = 2;
+ error = i;
+ min_uc = 0x800;
} else if ((ch&0xf8) == 0xf0) {
uc = ch & 0x07;
need = 3;
+ error = i;
+ min_uc = 0x10000;
+ } else {
+ // error
+ *qch++ = QChar::replacement;
}
}
}