Line
Link Here
|
0 |
-- src/codecs/qutfcodec.cpp |
0 |
++ src/codecs/qutfcodec.cpp |
Lines 154-159
Link Here
|
154 |
|
154 |
|
155 |
class QUtf8Decoder : public QTextDecoder { |
155 |
class QUtf8Decoder : public QTextDecoder { |
156 |
uint uc; |
156 |
uint uc; |
|
|
157 |
uint min_uc; |
157 |
int need; |
158 |
int need; |
158 |
bool headerDone; |
159 |
bool headerDone; |
159 |
public: |
160 |
public: |
Lines 167-174
Link Here
|
167 |
result.setLength( len ); // worst case |
168 |
result.setLength( len ); // worst case |
168 |
QChar *qch = (QChar *)result.unicode(); |
169 |
QChar *qch = (QChar *)result.unicode(); |
169 |
uchar ch; |
170 |
uchar ch; |
|
|
171 |
int error = -1; |
170 |
for (int i=0; i<len; i++) { |
172 |
for (int i=0; i<len; i++) { |
171 |
ch = *chars++; |
173 |
ch = chars[i]; |
172 |
if (need) { |
174 |
if (need) { |
173 |
if ( (ch&0xc0) == 0x80 ) { |
175 |
if ( (ch&0xc0) == 0x80 ) { |
174 |
uc = (uc << 6) | (ch & 0x3f); |
176 |
uc = (uc << 6) | (ch & 0x3f); |
Lines 182-187
Link Here
|
182 |
*qch++ = QChar(high); |
184 |
*qch++ = QChar(high); |
183 |
*qch++ = QChar(low); |
185 |
*qch++ = QChar(low); |
184 |
headerDone = TRUE; |
186 |
headerDone = TRUE; |
|
|
187 |
} else if ((uc < min_uc) || (uc >= 0xd800 && uc <= 0xdfff) || (uc >= 0xfffe)) { |
188 |
*qch++ = QChar::replacement; |
185 |
} else { |
189 |
} else { |
186 |
if (headerDone || QChar(uc) != QChar::byteOrderMark) |
190 |
if (headerDone || QChar(uc) != QChar::byteOrderMark) |
187 |
*qch++ = uc; |
191 |
*qch++ = uc; |
Lines 190-195
Link Here
|
190 |
} |
194 |
} |
191 |
} else { |
195 |
} else { |
192 |
// error |
196 |
// error |
|
|
197 |
i = error; |
193 |
*qch++ = QChar::replacement; |
198 |
*qch++ = QChar::replacement; |
194 |
need = 0; |
199 |
need = 0; |
195 |
} |
200 |
} |
Lines 200-211
Link Here
|
200 |
} else if ((ch & 0xe0) == 0xc0) { |
205 |
} else if ((ch & 0xe0) == 0xc0) { |
201 |
uc = ch & 0x1f; |
206 |
uc = ch & 0x1f; |
202 |
need = 1; |
207 |
need = 1; |
|
|
208 |
error = i; |
209 |
min_uc = 0x80; |
203 |
} else if ((ch & 0xf0) == 0xe0) { |
210 |
} else if ((ch & 0xf0) == 0xe0) { |
204 |
uc = ch & 0x0f; |
211 |
uc = ch & 0x0f; |
205 |
need = 2; |
212 |
need = 2; |
|
|
213 |
error = i; |
214 |
min_uc = 0x800; |
206 |
} else if ((ch&0xf8) == 0xf0) { |
215 |
} else if ((ch&0xf8) == 0xf0) { |
207 |
uc = ch & 0x07; |
216 |
uc = ch & 0x07; |
208 |
need = 3; |
217 |
need = 3; |
|
|
218 |
error = i; |
219 |
min_uc = 0x10000; |
220 |
} else { |
221 |
// error |
222 |
*qch++ = QChar::replacement; |
209 |
} |
223 |
} |
210 |
} |
224 |
} |
211 |
} |
225 |
} |
212 |
-- src/tools/qstring.cpp |
226 |
++ src/tools/qstring.cpp |
Lines 5805-5810
Link Here
|
5805 |
result.setLength( len ); // worst case |
5805 |
result.setLength( len ); // worst case |
5806 |
QChar *qch = (QChar *)result.unicode(); |
5806 |
QChar *qch = (QChar *)result.unicode(); |
5807 |
uint uc = 0; |
5807 |
uint uc = 0; |
|
|
5808 |
uint min_uc = 0; |
5808 |
int need = 0; |
5809 |
int need = 0; |
5809 |
int error = -1; |
5810 |
int error = -1; |
5810 |
uchar ch; |
5811 |
uchar ch; |
Lines 5822-5827
Link Here
|
5822 |
unsigned short low = uc%0x400 + 0xdc00; |
5823 |
unsigned short low = uc%0x400 + 0xdc00; |
5823 |
*qch++ = QChar(high); |
5824 |
*qch++ = QChar(high); |
5824 |
*qch++ = QChar(low); |
5825 |
*qch++ = QChar(low); |
|
|
5826 |
} else if (uc < min_uc || (uc >= 0xd800 && uc <= 0xdfff) || (uc >= 0xfffe)) { |
5827 |
// overlong seqence, UTF16 surrogate or BOM |
5828 |
i = error; |
5829 |
qch = addOne(qch, result); |
5830 |
*qch++ = QChar(0xdbff); |
5831 |
*qch++ = QChar(0xde00+((uchar)utf8[i])); |
5825 |
} else { |
5832 |
} else { |
5826 |
*qch++ = uc; |
5833 |
*qch++ = uc; |
5827 |
} |
5834 |
} |
Lines 5844-5857
Link Here
|
5844 |
uc = ch & 0x1f; |
5851 |
uc = ch & 0x1f; |
5845 |
need = 1; |
5852 |
need = 1; |
5846 |
error = i; |
5853 |
error = i; |
|
|
5854 |
min_uc = 0x80; |
5847 |
} else if ((ch & 0xf0) == 0xe0) { |
5855 |
} else if ((ch & 0xf0) == 0xe0) { |
5848 |
uc = ch & 0x0f; |
5856 |
uc = ch & 0x0f; |
5849 |
need = 2; |
5857 |
need = 2; |
5850 |
error = i; |
5858 |
error = i; |
|
|
5859 |
min_uc = 0x800; |
5851 |
} else if ((ch&0xf8) == 0xf0) { |
5860 |
} else if ((ch&0xf8) == 0xf0) { |
5852 |
uc = ch & 0x07; |
5861 |
uc = ch & 0x07; |
5853 |
need = 3; |
5862 |
need = 3; |
5854 |
error = i; |
5863 |
error = i; |
|
|
5864 |
min_uc = 0x10000; |
5855 |
} else { |
5865 |
} else { |
5856 |
// Error |
5866 |
// Error |
5857 |
qch = addOne(qch, result); |
5867 |
qch = addOne(qch, result); |