Line
Link Here
|
0 |
-- src/corelib/codecs/qutfcodec.cpp |
0 |
++ src/corelib/codecs/qutfcodec.cpp |
Lines 126-140
Link Here
|
126 |
bool headerdone = false; |
126 |
bool headerdone = false; |
127 |
QChar replacement = QChar::ReplacementCharacter; |
127 |
QChar replacement = QChar::ReplacementCharacter; |
128 |
int need = 0; |
128 |
int need = 0; |
|
|
129 |
int error = -1; |
129 |
uint uc = 0; |
130 |
uint uc = 0; |
|
|
131 |
uint min_uc = 0; |
130 |
if (state) { |
132 |
if (state) { |
131 |
if (state->flags & IgnoreHeader) |
133 |
if (state->flags & IgnoreHeader) |
132 |
headerdone = true; |
134 |
headerdone = true; |
133 |
if (state->flags & ConvertInvalidToNull) |
135 |
if (state->flags & ConvertInvalidToNull) |
134 |
replacement = QChar::Null; |
136 |
replacement = QChar::Null; |
135 |
need = state->remainingChars; |
137 |
need = state->remainingChars; |
136 |
if (need) |
138 |
if (need) { |
137 |
uc = state->state_data[0]; |
139 |
uc = state->state_data[0]; |
|
|
140 |
min_uc = state->state_data[1]; |
141 |
} |
138 |
} |
142 |
} |
139 |
if (!headerdone && len > 3 |
143 |
if (!headerdone && len > 3 |
140 |
&& (uchar)chars[0] == 0xef && (uchar)chars[1] == 0xbb && (uchar)chars[2] == 0xbf) { |
144 |
&& (uchar)chars[0] == 0xef && (uchar)chars[1] == 0xbb && (uchar)chars[2] == 0xbf) { |
Lines 144-157
Link Here
|
144 |
headerdone = true; |
148 |
headerdone = true; |
145 |
} |
149 |
} |
146 |
|
150 |
|
|
|
151 |
int originalLength = target->length(); |
147 |
QString &result = *target; |
152 |
QString &result = *target; |
148 |
result.resize(len); // worst case |
153 |
result.resize(originalLength + len); // worst case |
149 |
QChar *qch = result.data(); |
154 |
QChar *qch = result.data() + originalLength; |
150 |
uchar ch; |
155 |
uchar ch; |
151 |
int invalid = 0; |
156 |
int invalid = 0; |
152 |
|
157 |
|
153 |
for (int i=0; i<len; i++) { |
158 |
for (int i=0; i<len; i++) { |
154 |
ch = *chars++; |
159 |
ch = chars[i]; |
155 |
if (need) { |
160 |
if (need) { |
156 |
if ((ch&0xc0) == 0x80) { |
161 |
if ((ch&0xc0) == 0x80) { |
157 |
uc = (uc << 6) | (ch & 0x3f); |
162 |
uc = (uc << 6) | (ch & 0x3f); |
Lines 162-175
Link Here
|
162 |
uc -= 0x10000; |
167 |
uc -= 0x10000; |
163 |
unsigned short high = uc/0x400 + 0xd800; |
168 |
unsigned short high = uc/0x400 + 0xd800; |
164 |
unsigned short low = uc%0x400 + 0xdc00; |
169 |
unsigned short low = uc%0x400 + 0xdc00; |
|
|
170 |
|
171 |
// resize if necessary |
172 |
long where = qch - result.unicode(); |
173 |
if (where + 2 >= result.length()) { |
174 |
result.resize(where + 2); |
175 |
qch = result.data() + where; |
176 |
} |
177 |
|
165 |
*qch++ = QChar(high); |
178 |
*qch++ = QChar(high); |
166 |
*qch++ = QChar(low); |
179 |
*qch++ = QChar(low); |
|
|
180 |
} else if ((uc < min_uc) || (uc >= 0xd800 && uc <= 0xdfff) || (uc >= 0xfffe)) { |
181 |
// error |
182 |
*qch++ = QChar::ReplacementCharacter; |
183 |
++invalid; |
167 |
} else { |
184 |
} else { |
168 |
*qch++ = uc; |
185 |
*qch++ = uc; |
169 |
} |
186 |
} |
170 |
} |
187 |
} |
171 |
} else { |
188 |
} else { |
172 |
// error |
189 |
// error |
|
|
190 |
i = error; |
173 |
*qch++ = QChar::ReplacementCharacter; |
191 |
*qch++ = QChar::ReplacementCharacter; |
174 |
++invalid; |
192 |
++invalid; |
175 |
need = 0; |
193 |
need = 0; |
Lines 180-194
Link Here
|
180 |
} else if ((ch & 0xe0) == 0xc0) { |
198 |
} else if ((ch & 0xe0) == 0xc0) { |
181 |
uc = ch & 0x1f; |
199 |
uc = ch & 0x1f; |
182 |
need = 1; |
200 |
need = 1; |
|
|
201 |
error = i; |
202 |
min_uc = 0x80; |
183 |
} else if ((ch & 0xf0) == 0xe0) { |
203 |
} else if ((ch & 0xf0) == 0xe0) { |
184 |
uc = ch & 0x0f; |
204 |
uc = ch & 0x0f; |
185 |
need = 2; |
205 |
need = 2; |
|
|
206 |
error = i; |
207 |
min_uc = 0x800; |
186 |
} else if ((ch&0xf8) == 0xf0) { |
208 |
} else if ((ch&0xf8) == 0xf0) { |
187 |
uc = ch & 0x07; |
209 |
uc = ch & 0x07; |
188 |
need = 3; |
210 |
need = 3; |
|
|
211 |
error = i; |
212 |
min_uc = 0x10000; |
213 |
} else { |
214 |
// error |
215 |
*qch++ = QChar::ReplacementCharacter; |
216 |
++invalid; |
189 |
} |
217 |
} |
190 |
} |
218 |
} |
191 |
} |
219 |
} |
|
|
220 |
if (!state && need > 0) { |
221 |
// unterminated UTF sequence |
222 |
for (int i = error; i < len; ++i) { |
223 |
*qch++ = QChar::ReplacementCharacter; |
224 |
++invalid; |
225 |
} |
226 |
} |
192 |
result.truncate(qch - result.unicode()); |
227 |
result.truncate(qch - result.unicode()); |
193 |
if (state) { |
228 |
if (state) { |
194 |
state->invalidChars += invalid; |
229 |
state->invalidChars += invalid; |
Lines 196-201
Link Here
|
196 |
if (headerdone) |
231 |
if (headerdone) |
197 |
state->flags |= IgnoreHeader; |
232 |
state->flags |= IgnoreHeader; |
198 |
state->state_data[0] = need ? uc : 0; |
233 |
state->state_data[0] = need ? uc : 0; |
|
|
234 |
state->state_data[1] = need ? min_uc : 0; |
199 |
} |
235 |
} |
200 |
} |
236 |
} |
201 |
|
237 |
|
202 |
-- src/corelib/tools/qstring.cpp |
238 |
++ src/corelib/tools/qstring.cpp |
Lines 3416-3421
Link Here
|
3416 |
result.resize(size); // worst case |
3416 |
result.resize(size); // worst case |
3417 |
ushort *qch = result.d->data; |
3417 |
ushort *qch = result.d->data; |
3418 |
uint uc = 0; |
3418 |
uint uc = 0; |
|
|
3419 |
uint min_uc = 0; |
3419 |
int need = 0; |
3420 |
int need = 0; |
3420 |
int error = -1; |
3421 |
int error = -1; |
3421 |
uchar ch; |
3422 |
uchar ch; |
Lines 3430-3435
Link Here
|
3430 |
// surrogate pair |
3431 |
// surrogate pair |
3431 |
*qch++ = QChar::highSurrogate(uc); |
3432 |
*qch++ = QChar::highSurrogate(uc); |
3432 |
uc = QChar::lowSurrogate(uc); |
3433 |
uc = QChar::lowSurrogate(uc); |
|
|
3434 |
} else if ((uc < min_uc) || (uc >= 0xd800 && uc <= 0xdfff) || (uc >= 0xfffe)) { |
3435 |
// overlong seqence, UTF16 surrogate or BOM |
3436 |
i = error; |
3437 |
qch = addOne(qch, result); |
3438 |
*qch++ = 0xdbff; |
3439 |
uc = 0xde00 + ((uchar)str[i]); |
3433 |
} |
3440 |
} |
3434 |
*qch++ = uc; |
3441 |
*qch++ = uc; |
3435 |
} |
3442 |
} |
Lines 3451-3464
Link Here
|
3451 |
uc = ch & 0x1f; |
3458 |
uc = ch & 0x1f; |
3452 |
need = 1; |
3459 |
need = 1; |
3453 |
error = i; |
3460 |
error = i; |
|
|
3461 |
min_uc = 0x80; |
3454 |
} else if ((ch & 0xf0) == 0xe0) { |
3462 |
} else if ((ch & 0xf0) == 0xe0) { |
3455 |
uc = ch & 0x0f; |
3463 |
uc = ch & 0x0f; |
3456 |
need = 2; |
3464 |
need = 2; |
3457 |
error = i; |
3465 |
error = i; |
|
|
3466 |
min_uc = 0x800; |
3458 |
} else if ((ch&0xf8) == 0xf0) { |
3467 |
} else if ((ch&0xf8) == 0xf0) { |
3459 |
uc = ch & 0x07; |
3468 |
uc = ch & 0x07; |
3460 |
need = 3; |
3469 |
need = 3; |
3461 |
error = i; |
3470 |
error = i; |
|
|
3471 |
min_uc = 0x10000; |
3462 |
} else { |
3472 |
} else { |
3463 |
// Error |
3473 |
// Error |
3464 |
qch = addOne(qch, result); |
3474 |
qch = addOne(qch, result); |
Lines 6348-6353
Link Here
|
6348 |
|
6358 |
|
6349 |
|
6359 |
|
6350 |
/*! \fn QString &QString::inline_append(QChar ch) |
6360 |
/*! \fn QString &QString::inline_append(QChar ch) |
|
|
6361 |
\internal |
6351 |
|
6362 |
|
6352 |
An inlined version of append(). |
6363 |
An inlined version of append(). |
6353 |
*/ |
6364 |
*/ |