Magellan Linux

Annotation of /trunk/qt/patches/qt-3.3.8b-utf8-bug.patch

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1383 - (hide annotations) (download)
Thu Jun 30 08:12:09 2011 UTC (12 years, 11 months ago) by niro
File size: 2670 byte(s)
-added patch for an utf8 bug
1 niro 1383 --- src/codecs/qutfcodec.cpp
2     +++ src/codecs/qutfcodec.cpp
3     @@ -154,6 +154,7 @@
4    
5     class QUtf8Decoder : public QTextDecoder {
6     uint uc;
7     + uint min_uc;
8     int need;
9     bool headerDone;
10     public:
11     @@ -167,8 +168,9 @@
12     result.setLength( len ); // worst case
13     QChar *qch = (QChar *)result.unicode();
14     uchar ch;
15     + int error = -1;
16     for (int i=0; i<len; i++) {
17     - ch = *chars++;
18     + ch = chars[i];
19     if (need) {
20     if ( (ch&0xc0) == 0x80 ) {
21     uc = (uc << 6) | (ch & 0x3f);
22     @@ -182,6 +184,8 @@
23     *qch++ = QChar(high);
24     *qch++ = QChar(low);
25     headerDone = TRUE;
26     + } else if ((uc < min_uc) || (uc >= 0xd800 && uc <= 0xdfff) || (uc >= 0xfffe)) {
27     + *qch++ = QChar::replacement;
28     } else {
29     if (headerDone || QChar(uc) != QChar::byteOrderMark)
30     *qch++ = uc;
31     @@ -190,6 +194,7 @@
32     }
33     } else {
34     // error
35     + i = error;
36     *qch++ = QChar::replacement;
37     need = 0;
38     }
39     @@ -200,12 +205,21 @@
40     } else if ((ch & 0xe0) == 0xc0) {
41     uc = ch & 0x1f;
42     need = 1;
43     + error = i;
44     + min_uc = 0x80;
45     } else if ((ch & 0xf0) == 0xe0) {
46     uc = ch & 0x0f;
47     need = 2;
48     + error = i;
49     + min_uc = 0x800;
50     } else if ((ch&0xf8) == 0xf0) {
51     uc = ch & 0x07;
52     need = 3;
53     + error = i;
54     + min_uc = 0x10000;
55     + } else {
56     + // error
57     + *qch++ = QChar::replacement;
58     }
59     }
60     }
61     --- src/tools/qstring.cpp
62     +++ src/tools/qstring.cpp
63     @@ -5805,6 +5805,7 @@
64     result.setLength( len ); // worst case
65     QChar *qch = (QChar *)result.unicode();
66     uint uc = 0;
67     + uint min_uc = 0;
68     int need = 0;
69     int error = -1;
70     uchar ch;
71     @@ -5822,6 +5823,12 @@
72     unsigned short low = uc%0x400 + 0xdc00;
73     *qch++ = QChar(high);
74     *qch++ = QChar(low);
75     + } else if (uc < min_uc || (uc >= 0xd800 && uc <= 0xdfff) || (uc >= 0xfffe)) {
76     + // overlong seqence, UTF16 surrogate or BOM
77     + i = error;
78     + qch = addOne(qch, result);
79     + *qch++ = QChar(0xdbff);
80     + *qch++ = QChar(0xde00+((uchar)utf8[i]));
81     } else {
82     *qch++ = uc;
83     }
84     @@ -5844,14 +5851,17 @@
85     uc = ch & 0x1f;
86     need = 1;
87     error = i;
88     + min_uc = 0x80;
89     } else if ((ch & 0xf0) == 0xe0) {
90     uc = ch & 0x0f;
91     need = 2;
92     error = i;
93     + min_uc = 0x800;
94     } else if ((ch&0xf8) == 0xf0) {
95     uc = ch & 0x07;
96     need = 3;
97     error = i;
98     + min_uc = 0x10000;
99     } else {
100     // Error
101     qch = addOne(qch, result);