Line | Source Code | Coverage |
---|
1 | | - |
2 | | - |
3 | | - |
4 | | - |
5 | enum EncodingAction { | - |
6 | DecodeCharacter = 0, | - |
7 | LeaveCharacter = 1, | - |
8 | EncodeCharacter = 2 | - |
9 | }; | - |
10 | | - |
11 | | - |
12 | | - |
13 | | - |
14 | | - |
15 | | - |
16 | | - |
17 | static const uchar defaultActionTable[96] = { | - |
18 | 2, | - |
19 | 1, | - |
20 | 2, | - |
21 | 1, | - |
22 | 1, | - |
23 | 2, | - |
24 | 1, | - |
25 | 1, | - |
26 | 1, | - |
27 | 1, | - |
28 | 1, | - |
29 | 1, | - |
30 | 1, | - |
31 | 0, | - |
32 | 0, | - |
33 | 1, | - |
34 | | - |
35 | 0, 0, 0, 0, 0, | - |
36 | 0, 0, 0, 0, 0, | - |
37 | 1, | - |
38 | 1, | - |
39 | 2, | - |
40 | 1, | - |
41 | 2, | - |
42 | 1, | - |
43 | | - |
44 | 1, | - |
45 | 0, 0, 0, 0, 0, | - |
46 | 0, 0, 0, 0, 0, | - |
47 | 0, 0, 0, 0, 0, | - |
48 | 0, 0, 0, 0, 0, | - |
49 | 0, 0, 0, 0, 0, 0, | - |
50 | 1, | - |
51 | 2, | - |
52 | 1, | - |
53 | 2, | - |
54 | 0, | - |
55 | | - |
56 | 2, | - |
57 | 0, 0, 0, 0, 0, | - |
58 | 0, 0, 0, 0, 0, | - |
59 | 0, 0, 0, 0, 0, | - |
60 | 0, 0, 0, 0, 0, | - |
61 | 0, 0, 0, 0, 0, 0, | - |
62 | 2, | - |
63 | 2, | - |
64 | 2, | - |
65 | 0, | - |
66 | | - |
67 | 2 | - |
68 | }; | - |
69 | | - |
70 | | - |
71 | | - |
72 | | - |
73 | | - |
74 | static const uchar delimsMask[96] = { | - |
75 | 0xff, | - |
76 | 0x00, | - |
77 | 0xff, | - |
78 | 0x00, | - |
79 | 0x00, | - |
80 | 0xff, | - |
81 | 0x00, | - |
82 | 0x00, | - |
83 | 0x00, | - |
84 | 0x00, | - |
85 | 0x00, | - |
86 | 0x00, | - |
87 | 0x00, | - |
88 | 0xff, | - |
89 | 0xff, | - |
90 | 0x00, | - |
91 | | - |
92 | 0xff, 0xff, 0xff, 0xff, 0xff, | - |
93 | 0xff, 0xff, 0xff, 0xff, 0xff, | - |
94 | 0x00, | - |
95 | 0x00, | - |
96 | 0xff, | - |
97 | 0x00, | - |
98 | 0xff, | - |
99 | 0x00, | - |
100 | | - |
101 | 0x00, | - |
102 | 0xff, 0xff, 0xff, 0xff, 0xff, | - |
103 | 0xff, 0xff, 0xff, 0xff, 0xff, | - |
104 | 0xff, 0xff, 0xff, 0xff, 0xff, | - |
105 | 0xff, 0xff, 0xff, 0xff, 0xff, | - |
106 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, | - |
107 | 0x00, | - |
108 | 0xff, | - |
109 | 0x00, | - |
110 | 0xff, | - |
111 | 0xff, | - |
112 | | - |
113 | 0xff, | - |
114 | 0xff, 0xff, 0xff, 0xff, 0xff, | - |
115 | 0xff, 0xff, 0xff, 0xff, 0xff, | - |
116 | 0xff, 0xff, 0xff, 0xff, 0xff, | - |
117 | 0xff, 0xff, 0xff, 0xff, 0xff, | - |
118 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, | - |
119 | 0xff, | - |
120 | 0xff, | - |
121 | 0xff, | - |
122 | 0xff, | - |
123 | | - |
124 | 0xff | - |
125 | }; | - |
126 | | - |
127 | static const uchar reservedMask[96] = { | - |
128 | 0xff, | - |
129 | 0xff, | - |
130 | 0x00, | - |
131 | 0xff, | - |
132 | 0xff, | - |
133 | 0xff, | - |
134 | 0xff, | - |
135 | 0xff, | - |
136 | 0xff, | - |
137 | 0xff, | - |
138 | 0xff, | - |
139 | 0xff, | - |
140 | 0xff, | - |
141 | 0xff, | - |
142 | 0xff, | - |
143 | 0xff, | - |
144 | | - |
145 | 0xff, 0xff, 0xff, 0xff, 0xff, | - |
146 | 0xff, 0xff, 0xff, 0xff, 0xff, | - |
147 | 0xff, | - |
148 | 0xff, | - |
149 | 0x00, | - |
150 | 0xff, | - |
151 | 0x00, | - |
152 | 0xff, | - |
153 | | - |
154 | 0xff, | - |
155 | 0xff, 0xff, 0xff, 0xff, 0xff, | - |
156 | 0xff, 0xff, 0xff, 0xff, 0xff, | - |
157 | 0xff, 0xff, 0xff, 0xff, 0xff, | - |
158 | 0xff, 0xff, 0xff, 0xff, 0xff, | - |
159 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, | - |
160 | 0xff, | - |
161 | 0x00, | - |
162 | 0xff, | - |
163 | 0x00, | - |
164 | 0xff, | - |
165 | | - |
166 | 0x00, | - |
167 | 0xff, 0xff, 0xff, 0xff, 0xff, | - |
168 | 0xff, 0xff, 0xff, 0xff, 0xff, | - |
169 | 0xff, 0xff, 0xff, 0xff, 0xff, | - |
170 | 0xff, 0xff, 0xff, 0xff, 0xff, | - |
171 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, | - |
172 | 0x00, | - |
173 | 0x00, | - |
174 | 0x00, | - |
175 | 0xff, | - |
176 | | - |
177 | 0xff | - |
178 | }; | - |
179 | | - |
180 | static inline bool isHex(ushort c) | - |
181 | { | - |
182 | return (c >= 'a' && c <= 'f') || | 2640 |
183 | (c >= 'A' && c <= 'F') || | 2640 |
184 | (c >= '0' && c <= '9'); executed: return (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F') || (c >= '0' && c <= '9'); Execution Count:2640 | 2640 |
185 | } | - |
186 | | - |
187 | static inline bool isUpperHex(ushort c) | - |
188 | { | - |
189 | | - |
190 | return c < 0x60; executed: return c < 0x60; Execution Count:1563 | 1563 |
191 | } | - |
192 | | - |
193 | static inline ushort toUpperHex(ushort c) | - |
194 | { | - |
195 | return isUpperHex(c) ? c : c - 0x20; executed: return isUpperHex(c) ? c : c - 0x20; Execution Count:240 | 240 |
196 | } | - |
197 | | - |
198 | static inline ushort decodeNibble(ushort c) | - |
199 | { | - |
200 | return c >= 'a' ? c - 'a' + 0xA : | 2608 |
201 | c >= 'A' ? c - 'A' + 0xA : c - '0'; executed: return c >= 'a' ? c - 'a' + 0xA : c >= 'A' ? c - 'A' + 0xA : c - '0'; Execution Count:2608 | 2608 |
202 | } | - |
203 | | - |
204 | | - |
205 | | - |
206 | | - |
207 | static inline ushort decodePercentEncoding(const ushort *input) | - |
208 | { | - |
209 | ushort c1 = input[1]; | - |
210 | ushort c2 = input[2]; | - |
211 | if (!isHex(c1) || !isHex(c2)) evaluated: !isHex(c1) yes Evaluation Count:22 | yes Evaluation Count:1309 |
evaluated: !isHex(c2) yes Evaluation Count:18 | yes Evaluation Count:1291 |
| 18-1309 |
212 | return ushort(-1); executed: return ushort(-1); Execution Count:40 | 40 |
213 | return decodeNibble(c1) << 4 | decodeNibble(c2); executed: return decodeNibble(c1) << 4 | decodeNibble(c2); Execution Count:1291 | 1291 |
214 | } | - |
215 | | - |
216 | static inline ushort encodeNibble(ushort c) | - |
217 | { | - |
218 | static const uchar hexnumbers[] = "0123456789ABCDEF"; | - |
219 | return hexnumbers[c & 0xf]; executed: return hexnumbers[c & 0xf]; Execution Count:4327 | 4327 |
220 | } | - |
221 | | - |
222 | static void ensureDetached(QString &result, ushort *&output, const ushort *begin, const ushort *input, const ushort *end, | - |
223 | int add = 0) | - |
224 | { | - |
225 | if (!output) { evaluated: !output yes Evaluation Count:1376 | yes Evaluation Count:1319 |
| 1319-1376 |
226 | | - |
227 | | - |
228 | int charsProcessed = input - begin; | - |
229 | int charsRemaining = end - input; | - |
230 | int spaceNeeded = end - begin + 2 * charsRemaining + add; | - |
231 | int origSize = result.size(); | - |
232 | result.resize(origSize + spaceNeeded); | - |
233 | | - |
234 | | - |
235 | output = const_cast<ushort *>(reinterpret_cast<const ushort *>(result.constData())) | - |
236 | + origSize; | - |
237 | | - |
238 | | - |
239 | int i; | - |
240 | for (i = 0; i < charsProcessed; ++i) evaluated: i < charsProcessed yes Evaluation Count:10159 | yes Evaluation Count:1376 |
| 1376-10159 |
241 | output[i] = begin[i]; executed: output[i] = begin[i]; Execution Count:10159 | 10159 |
242 | output += i; | - |
243 | } executed: } Execution Count:1376 | 1376 |
244 | } executed: } Execution Count:2695 | 2695 |
245 | | - |
246 | | - |
247 | static bool encodedUtf8ToUtf16(QString &result, ushort *&output, const ushort *begin, const ushort *&input, | - |
248 | const ushort *end, ushort decoded) | - |
249 | { | - |
250 | int charsNeeded; | - |
251 | uint min_uc; | - |
252 | uint uc; | - |
253 | | - |
254 | if (decoded <= 0xC1) { evaluated: decoded <= 0xC1 yes Evaluation Count:22 | yes Evaluation Count:83 |
| 22-83 |
255 | | - |
256 | | - |
257 | return false; executed: return false; Execution Count:22 | 22 |
258 | } else if (decoded < 0xe0) { evaluated: decoded < 0xe0 yes Evaluation Count:71 | yes Evaluation Count:12 |
| 12-71 |
259 | charsNeeded = 2; | - |
260 | min_uc = 0x80; | - |
261 | uc = decoded & 0x1f; | - |
262 | } else if (decoded < 0xf0) { executed: } Execution Count:71 evaluated: decoded < 0xf0 yes Evaluation Count:10 | yes Evaluation Count:2 |
| 2-71 |
263 | charsNeeded = 3; | - |
264 | min_uc = 0x800; | - |
265 | uc = decoded & 0x0f; | - |
266 | } else if (decoded < 0xf5) { executed: } Execution Count:10 partially evaluated: decoded < 0xf5 yes Evaluation Count:2 | no Evaluation Count:0 |
| 0-10 |
267 | charsNeeded = 4; | - |
268 | min_uc = 0x10000; | - |
269 | uc = decoded & 0x07; | - |
270 | } else { executed: } Execution Count:2 | 2 |
271 | | - |
272 | | - |
273 | | - |
274 | return false; never executed: return false; | 0 |
275 | } | - |
276 | | - |
277 | | - |
278 | if (end - input < 3*charsNeeded) evaluated: end - input < 3*charsNeeded yes Evaluation Count:6 | yes Evaluation Count:77 |
| 6-77 |
279 | return false; executed: return false; Execution Count:6 | 6 |
280 | | - |
281 | if (input[3] != '%') evaluated: input[3] != '%' yes Evaluation Count:1 | yes Evaluation Count:76 |
| 1-76 |
282 | return false; executed: return false; Execution Count:1 | 1 |
283 | | - |
284 | | - |
285 | decoded = decodePercentEncoding(input + 3); | - |
286 | if ((decoded & 0xc0) != 0x80) evaluated: (decoded & 0xc0) != 0x80 yes Evaluation Count:18 | yes Evaluation Count:58 |
| 18-58 |
287 | return false; executed: return false; Execution Count:18 | 18 |
288 | uc <<= 6; | - |
289 | uc |= decoded & 0x3f; | - |
290 | | - |
291 | if (charsNeeded > 2) { evaluated: charsNeeded > 2 yes Evaluation Count:5 | yes Evaluation Count:53 |
| 5-53 |
292 | if (input[6] != '%') partially evaluated: input[6] != '%' no Evaluation Count:0 | yes Evaluation Count:5 |
| 0-5 |
293 | return false; never executed: return false; | 0 |
294 | | - |
295 | | - |
296 | decoded = decodePercentEncoding(input + 6); | - |
297 | if ((decoded & 0xc0) != 0x80) partially evaluated: (decoded & 0xc0) != 0x80 no Evaluation Count:0 | yes Evaluation Count:5 |
| 0-5 |
298 | return false; never executed: return false; | 0 |
299 | uc <<= 6; | - |
300 | uc |= decoded & 0x3f; | - |
301 | | - |
302 | if (charsNeeded > 3) { evaluated: charsNeeded > 3 yes Evaluation Count:2 | yes Evaluation Count:3 |
| 2-3 |
303 | if (input[9] != '%') partially evaluated: input[9] != '%' no Evaluation Count:0 | yes Evaluation Count:2 |
| 0-2 |
304 | return false; never executed: return false; | 0 |
305 | | - |
306 | | - |
307 | decoded = decodePercentEncoding(input + 9); | - |
308 | if ((decoded & 0xc0) != 0x80) partially evaluated: (decoded & 0xc0) != 0x80 no Evaluation Count:0 | yes Evaluation Count:2 |
| 0-2 |
309 | return false; never executed: return false; | 0 |
310 | uc <<= 6; | - |
311 | uc |= decoded & 0x3f; | - |
312 | } executed: } Execution Count:2 | 2 |
313 | } executed: } Execution Count:5 | 5 |
314 | | - |
315 | | - |
316 | if (uc < min_uc) partially evaluated: uc < min_uc no Evaluation Count:0 | yes Evaluation Count:58 |
| 0-58 |
317 | return false; never executed: return false; | 0 |
318 | if (QChar::isSurrogate(uc) || QChar::isNonCharacter(uc) || uc > QChar::LastValidCodePoint) partially evaluated: QChar::isSurrogate(uc) no Evaluation Count:0 | yes Evaluation Count:58 |
partially evaluated: QChar::isNonCharacter(uc) no Evaluation Count:0 | yes Evaluation Count:58 |
partially evaluated: uc > QChar::LastValidCodePoint no Evaluation Count:0 | yes Evaluation Count:58 |
| 0-58 |
319 | return false; never executed: return false; | 0 |
320 | | - |
321 | if (!QChar::requiresSurrogates(uc)) { evaluated: !QChar::requiresSurrogates(uc) yes Evaluation Count:56 | yes Evaluation Count:2 |
| 2-56 |
322 | | - |
323 | | - |
324 | ensureDetached(result, output, begin, input, end, -9 * charsNeeded + 1); | - |
325 | *output++ = uc; | - |
326 | } else { executed: } Execution Count:56 | 56 |
327 | | - |
328 | ensureDetached(result, output, begin, input, end, -9 * charsNeeded + 2); | - |
329 | *output++ = QChar::highSurrogate(uc); | - |
330 | *output++ = QChar::lowSurrogate(uc); | - |
331 | } executed: } Execution Count:2 | 2 |
332 | input += charsNeeded * 3 - 1; | - |
333 | return true; executed: return true; Execution Count:58 | 58 |
334 | } | - |
335 | | - |
336 | static void unicodeToEncodedUtf8(QString &result, ushort *&output, const ushort *begin, | - |
337 | const ushort *&input, const ushort *end, ushort decoded) | - |
338 | { | - |
339 | uint uc = decoded; | - |
340 | if (QChar::isHighSurrogate(uc)) { evaluated: QChar::isHighSurrogate(uc) yes Evaluation Count:8 | yes Evaluation Count:70 |
| 8-70 |
341 | if (input < end && QChar::isLowSurrogate(input[1])) partially evaluated: input < end yes Evaluation Count:8 | no Evaluation Count:0 |
partially evaluated: QChar::isLowSurrogate(input[1]) yes Evaluation Count:8 | no Evaluation Count:0 |
| 0-8 |
342 | uc = QChar::surrogateToUcs4(uc, input[1]); executed: uc = QChar::surrogateToUcs4(uc, input[1]); Execution Count:8 | 8 |
343 | } executed: } Execution Count:8 | 8 |
344 | | - |
345 | | - |
346 | | - |
347 | | - |
348 | | - |
349 | int utf8len = uc >= 0x10000 ? 4 : uc >= 0x800 ? 3 : 2; evaluated: uc >= 0x10000 yes Evaluation Count:8 | yes Evaluation Count:70 |
| 8-70 |
350 | | - |
351 | | - |
352 | if (!output) { evaluated: !output yes Evaluation Count:69 | yes Evaluation Count:9 |
| 9-69 |
353 | | - |
354 | | - |
355 | ensureDetached(result, output, begin, input, end, 3*utf8len - 3); | - |
356 | } else { executed: } Execution Count:69 | 69 |
357 | | - |
358 | int charsRemaining = end - input - 1; | - |
359 | int pos = output - reinterpret_cast<const ushort *>(result.constData()); | - |
360 | int spaceRemaining = result.size() - pos; | - |
361 | if (spaceRemaining < 3*charsRemaining + 3*utf8len) { evaluated: spaceRemaining < 3*charsRemaining + 3*utf8len yes Evaluation Count:5 | yes Evaluation Count:4 |
| 4-5 |
362 | | - |
363 | result.resize(result.size() + 3*utf8len); | - |
364 | | - |
365 | | - |
366 | output = const_cast<ushort *>(reinterpret_cast<const ushort *>(result.constData())); | - |
367 | output += pos; | - |
368 | } executed: } Execution Count:5 | 5 |
369 | } executed: } Execution Count:9 | 9 |
370 | | - |
371 | | - |
372 | if (uc < 0x800) { evaluated: uc < 0x800 yes Evaluation Count:61 | yes Evaluation Count:17 |
| 17-61 |
373 | | - |
374 | uchar c = 0xc0 | uchar(uc >> 6); | - |
375 | *output++ = '%'; | - |
376 | *output++ = encodeNibble(c >> 4); | - |
377 | *output++ = encodeNibble(c & 0xf); | - |
378 | } else { executed: } Execution Count:61 | 61 |
379 | uchar c; | - |
380 | if (uc > 0xFFFF) { evaluated: uc > 0xFFFF yes Evaluation Count:8 | yes Evaluation Count:9 |
| 8-9 |
381 | | - |
382 | c = 0xf0 | uchar(uc >> 18); | - |
383 | *output++ = '%'; | - |
384 | *output++ = 'F'; | - |
385 | *output++ = encodeNibble(c & 0xf); | - |
386 | | - |
387 | | - |
388 | c = 0x80 | (uchar(uc >> 12) & 0x3f); | - |
389 | *output++ = '%'; | - |
390 | *output++ = encodeNibble(c >> 4); | - |
391 | *output++ = encodeNibble(c & 0xf); | - |
392 | | - |
393 | | - |
394 | ++input; | - |
395 | } else { executed: } Execution Count:8 | 8 |
396 | | - |
397 | c = 0xe0 | uchar(uc >> 12); | - |
398 | *output++ = '%'; | - |
399 | *output++ = 'E'; | - |
400 | *output++ = encodeNibble(c & 0xf); | - |
401 | } executed: } Execution Count:9 | 9 |
402 | | - |
403 | | - |
404 | c = 0x80 | (uchar(uc >> 6) & 0x3f); | - |
405 | *output++ = '%'; | - |
406 | *output++ = encodeNibble(c >> 4); | - |
407 | *output++ = encodeNibble(c & 0xf); | - |
408 | } executed: } Execution Count:17 | 17 |
409 | | - |
410 | | - |
411 | uchar c = 0x80 | (uc & 0x3f); | - |
412 | *output++ = '%'; | - |
413 | *output++ = encodeNibble(c >> 4); | - |
414 | *output++ = encodeNibble(c & 0xf); | - |
415 | } executed: } Execution Count:78 | 78 |
416 | | - |
417 | static int recode(QString &result, const ushort *begin, const ushort *end, QUrl::ComponentFormattingOptions encoding, | - |
418 | const uchar *actionTable, bool retryBadEncoding) | - |
419 | { | - |
420 | const int origSize = result.size(); | - |
421 | const ushort *input = begin; | - |
422 | ushort *output = 0; | - |
423 | | - |
424 | for ( ; input != end; ++input) { evaluated: input != end yes Evaluation Count:24246 | yes Evaluation Count:7220 |
| 7220-24246 |
425 | register ushort c; | - |
426 | EncodingAction action; | - |
427 | | - |
428 | | - |
429 | for ( ; input != end; ++input) { evaluated: input != end yes Evaluation Count:374852 | yes Evaluation Count:20767 |
| 20767-374852 |
430 | c = *input; | - |
431 | if (c < 0x20U) evaluated: c < 0x20U yes Evaluation Count:7 | yes Evaluation Count:374914 |
| 7-374914 |
432 | action = EncodeCharacter; executed: action = EncodeCharacter; Execution Count:7 | 7 |
433 | if (c < 0x20U || c >= 0x80U) evaluated: c < 0x20U yes Evaluation Count:7 | yes Evaluation Count:374761 |
evaluated: c >= 0x80U yes Evaluation Count:239 | yes Evaluation Count:374764 |
| 7-374764 |
434 | goto non_trivial; executed: goto non_trivial; Execution Count:246 | 246 |
435 | action = EncodingAction(actionTable[c - ' ']); | - |
436 | if (action == EncodeCharacter) evaluated: action == EncodeCharacter yes Evaluation Count:3321 | yes Evaluation Count:371446 |
| 3321-371446 |
437 | goto non_trivial; executed: goto non_trivial; Execution Count:3321 | 3321 |
438 | if (output) evaluated: output yes Evaluation Count:7909 | yes Evaluation Count:363482 |
| 7909-363482 |
439 | *output++ = c; executed: *output++ = c; Execution Count:7909 | 7909 |
440 | } executed: } Execution Count:371325 | 371325 |
441 | break; executed: break; Execution Count:20769 | 20769 |
442 | | - |
443 | non_trivial: | - |
444 | register uint decoded; | - |
445 | if (c == '%' && retryBadEncoding) { evaluated: c == '%' yes Evaluation Count:1341 | yes Evaluation Count:2226 |
evaluated: retryBadEncoding yes Evaluation Count:70 | yes Evaluation Count:1271 |
| 70-2226 |
446 | | - |
447 | ensureDetached(result, output, begin, input, end); | - |
448 | *output++ = '%'; | - |
449 | *output++ = '2'; | - |
450 | *output++ = '5'; | - |
451 | continue; executed: continue; Execution Count:70 | 70 |
452 | } else if (c == '%') { evaluated: c == '%' yes Evaluation Count:1271 | yes Evaluation Count:2226 |
| 1271-2226 |
453 | | - |
454 | if (input + 2 >= end || (decoded = decodePercentEncoding(input)) == ushort(-1)) { evaluated: input + 2 >= end yes Evaluation Count:23 | yes Evaluation Count:1248 |
evaluated: (decoded = decodePercentEncoding(input)) == ushort(-1) yes Evaluation Count:40 | yes Evaluation Count:1208 |
| 23-1248 |
455 | | - |
456 | result.resize(origSize); | - |
457 | return recode(result, begin, end, encoding, actionTable, true); executed: return recode(result, begin, end, encoding, actionTable, true); Execution Count:63 | 63 |
458 | } | - |
459 | | - |
460 | if (decoded >= 0x80) { evaluated: decoded >= 0x80 yes Evaluation Count:126 | yes Evaluation Count:1082 |
| 126-1082 |
461 | | - |
462 | if (!(encoding & QUrl::EncodeUnicode) && evaluated: !(encoding & QUrl::EncodeUnicode) yes Evaluation Count:105 | yes Evaluation Count:21 |
| 21-105 |
463 | encodedUtf8ToUtf16(result, output, begin, input, end, decoded)) evaluated: encodedUtf8ToUtf16(result, output, begin, input, end, decoded) yes Evaluation Count:58 | yes Evaluation Count:47 |
| 47-58 |
464 | continue; executed: continue; Execution Count:58 | 58 |
465 | | - |
466 | | - |
467 | action = LeaveCharacter; | - |
468 | } else if (decoded >= 0x20) { evaluated: decoded >= 0x20 yes Evaluation Count:935 | yes Evaluation Count:147 |
executed: } Execution Count:68 | 68-935 |
469 | action = EncodingAction(actionTable[decoded - ' ']); | - |
470 | } executed: } Execution Count:935 | 935 |
471 | } else { | - |
472 | decoded = c; | - |
473 | if (decoded >= 0x80 && encoding & QUrl::EncodeUnicode) { evaluated: decoded >= 0x80 yes Evaluation Count:239 | yes Evaluation Count:1987 |
evaluated: encoding & QUrl::EncodeUnicode yes Evaluation Count:78 | yes Evaluation Count:161 |
| 78-1987 |
474 | | - |
475 | unicodeToEncodedUtf8(result, output, begin, input, end, decoded); | - |
476 | continue; executed: continue; Execution Count:78 | 78 |
477 | } else if (decoded >= 0x80) { evaluated: decoded >= 0x80 yes Evaluation Count:161 | yes Evaluation Count:1987 |
| 161-1987 |
478 | if (output) partially evaluated: output no Evaluation Count:0 | yes Evaluation Count:161 |
| 0-161 |
479 | *output++ = c; never executed: *output++ = c; | 0 |
480 | continue; executed: continue; Execution Count:161 | 161 |
481 | } | - |
482 | } | - |
483 | | - |
484 | | - |
485 | | - |
486 | | - |
487 | | - |
488 | | - |
489 | | - |
490 | if (c == '%' && action != DecodeCharacter) { evaluated: c == '%' yes Evaluation Count:1150 | yes Evaluation Count:1987 |
evaluated: action != DecodeCharacter yes Evaluation Count:759 | yes Evaluation Count:391 |
| 391-1987 |
491 | | - |
492 | | - |
493 | if (output || !isUpperHex(input[1]) || !isUpperHex(input[2])) { evaluated: output yes Evaluation Count:95 | yes Evaluation Count:664 |
evaluated: !isUpperHex(input[1]) yes Evaluation Count:5 | yes Evaluation Count:659 |
evaluated: !isUpperHex(input[2]) yes Evaluation Count:20 | yes Evaluation Count:639 |
| 5-664 |
494 | ensureDetached(result, output, begin, input, end); | - |
495 | *output++ = '%'; | - |
496 | *output++ = toUpperHex(*++input); | - |
497 | *output++ = toUpperHex(*++input); | - |
498 | } executed: } Execution Count:120 | 120 |
499 | } else if (c == '%' && action == DecodeCharacter) { evaluated: c == '%' yes Evaluation Count:391 | yes Evaluation Count:1987 |
partially evaluated: action == DecodeCharacter yes Evaluation Count:391 | no Evaluation Count:0 |
executed: } Execution Count:759 | 0-1987 |
500 | | - |
501 | ensureDetached(result, output, begin, input, end); | - |
502 | *output++ = decoded; | - |
503 | input += 2; | - |
504 | } else { executed: } Execution Count:391 | 391 |
505 | | - |
506 | ensureDetached(result, output, begin, input, end); | - |
507 | *output++ = '%'; | - |
508 | *output++ = encodeNibble(c >> 4); | - |
509 | *output++ = encodeNibble(c & 0xf); | - |
510 | } executed: } Execution Count:1987 | 1987 |
511 | } | - |
512 | | - |
513 | if (output) { evaluated: output yes Evaluation Count:1375 | yes Evaluation Count:26578 |
| 1375-26578 |
514 | int len = output - reinterpret_cast<const ushort *>(result.constData()); | - |
515 | result.truncate(len); | - |
516 | return len - origSize; executed: return len - origSize; Execution Count:1375 | 1375 |
517 | } | - |
518 | return 0; executed: return 0; Execution Count:26575 | 26575 |
519 | } | - |
520 | | - |
521 | static int decode(QString &appendTo, const ushort *begin, const ushort *end) | - |
522 | { | - |
523 | const int origSize = appendTo.size(); | - |
524 | const ushort *input = begin; | - |
525 | ushort *output = 0; | - |
526 | while (input != end) { evaluated: input != end yes Evaluation Count:351310 | yes Evaluation Count:6322 |
| 6322-351310 |
527 | if (*input != '%') { evaluated: *input != '%' yes Evaluation Count:351297 | yes Evaluation Count:13 |
| 13-351297 |
528 | if (output) evaluated: output yes Evaluation Count:38 | yes Evaluation Count:351259 |
| 38-351259 |
529 | *output++ = *input; executed: *output++ = *input; Execution Count:38 | 38 |
530 | ++input; | - |
531 | continue; executed: continue; Execution Count:351297 | 351297 |
532 | } | - |
533 | | - |
534 | if (__builtin_expect(!!(!output), false)) { evaluated: __builtin_expect(!!(!output), false) yes Evaluation Count:11 | yes Evaluation Count:2 |
| 2-11 |
535 | | - |
536 | appendTo.resize(origSize + (end - begin)); | - |
537 | output = reinterpret_cast<ushort *>(appendTo.begin()) + origSize; | - |
538 | memcpy(output, begin, (input - begin) * sizeof(ushort)); | - |
539 | output += input - begin; | - |
540 | } executed: } Execution Count:11 | 11 |
541 | | - |
542 | ++input; | - |
543 | qt_noop(); | - |
544 | qt_noop(); | - |
545 | qt_noop(); | - |
546 | *output++ = decodeNibble(input[0]) << 4 | decodeNibble(input[1]); | - |
547 | input += 2; | - |
548 | } executed: } Execution Count:13 | 13 |
549 | | - |
550 | if (output) { evaluated: output yes Evaluation Count:11 | yes Evaluation Count:6311 |
| 11-6311 |
551 | int len = output - reinterpret_cast<ushort *>(appendTo.begin()); | - |
552 | appendTo.truncate(len); | - |
553 | return len - origSize; executed: return len - origSize; Execution Count:11 | 11 |
554 | } | - |
555 | return 0; executed: return 0; Execution Count:6311 | 6311 |
556 | } | - |
557 | | - |
558 | template <size_t N> | - |
559 | static void maskTable(uchar (&table)[N], const uchar (&mask)[N]) | - |
560 | { | - |
561 | for (size_t i = 0; i < N; ++i) evaluated: i < N yes Evaluation Count:170213 | yes Evaluation Count:1785 |
| 1785-170213 |
562 | table[i] &= mask[i]; executed: table[i] &= mask[i]; Execution Count:170115 | 170115 |
563 | } executed: } Execution Count:1785 | 1785 |
564 | int | - |
565 | qt_urlRecode(QString &appendTo, const QChar *begin, const QChar *end, | - |
566 | QUrl::ComponentFormattingOptions encoding, const ushort *tableModifications) | - |
567 | { | - |
568 | uchar actionTable[sizeof defaultActionTable]; | - |
569 | if (encoding == QUrl::FullyDecoded) { evaluated: encoding == QUrl::FullyDecoded yes Evaluation Count:6322 | yes Evaluation Count:27896 |
| 6322-27896 |
570 | return decode(appendTo, reinterpret_cast<const ushort *>(begin), reinterpret_cast<const ushort *>(end)); executed: return decode(appendTo, reinterpret_cast<const ushort *>(begin), reinterpret_cast<const ushort *>(end)); Execution Count:6322 | 6322 |
571 | } | - |
572 | | - |
573 | if (!(encoding & QUrl::EncodeDelimiters) && encoding & QUrl::DecodeReserved) { evaluated: !(encoding & QUrl::EncodeDelimiters) yes Evaluation Count:22260 | yes Evaluation Count:5633 |
evaluated: encoding & QUrl::DecodeReserved yes Evaluation Count:20544 | yes Evaluation Count:1753 |
| 1753-22260 |
574 | | - |
575 | memset(actionTable, DecodeCharacter, sizeof actionTable); | - |
576 | if (encoding & QUrl::EncodeSpaces) evaluated: encoding & QUrl::EncodeSpaces yes Evaluation Count:8 | yes Evaluation Count:20504 |
| 8-20504 |
577 | actionTable[0] = EncodeCharacter; executed: actionTable[0] = EncodeCharacter; Execution Count:8 | 8 |
578 | | - |
579 | | - |
580 | actionTable['%' - ' '] = EncodeCharacter; | - |
581 | actionTable[0x7F - ' '] = EncodeCharacter; | - |
582 | } else { executed: } Execution Count:20499 | 20499 |
583 | memcpy(actionTable, defaultActionTable, sizeof actionTable); | - |
584 | if (!(encoding & QUrl::EncodeDelimiters)) evaluated: !(encoding & QUrl::EncodeDelimiters) yes Evaluation Count:1747 | yes Evaluation Count:5633 |
| 1747-5633 |
585 | maskTable(actionTable, delimsMask); executed: maskTable(actionTable, delimsMask); Execution Count:1747 | 1747 |
586 | if (encoding & QUrl::DecodeReserved) evaluated: encoding & QUrl::DecodeReserved yes Evaluation Count:26 | yes Evaluation Count:7365 |
| 26-7365 |
587 | maskTable(actionTable, reservedMask); executed: maskTable(actionTable, reservedMask); Execution Count:26 | 26 |
588 | if (!(encoding & QUrl::EncodeSpaces)) evaluated: !(encoding & QUrl::EncodeSpaces) yes Evaluation Count:2229 | yes Evaluation Count:5162 |
| 2229-5162 |
589 | actionTable[0] = DecodeCharacter; executed: actionTable[0] = DecodeCharacter; Execution Count:2229 | 2229 |
590 | } executed: } Execution Count:7391 | 7391 |
591 | | - |
592 | if (tableModifications) { evaluated: tableModifications yes Evaluation Count:17787 | yes Evaluation Count:10161 |
| 10161-17787 |
593 | for (const ushort *p = tableModifications; *p; ++p) evaluated: *p yes Evaluation Count:50028 | yes Evaluation Count:17796 |
| 17796-50028 |
594 | actionTable[uchar(*p) - ' '] = *p >> 8; executed: actionTable[uchar(*p) - ' '] = *p >> 8; Execution Count:50020 | 50020 |
595 | } executed: } Execution Count:17802 | 17802 |
596 | | - |
597 | return recode(appendTo, reinterpret_cast<const ushort *>(begin), reinterpret_cast<const ushort *>(end), | 27940 |
598 | encoding, actionTable, false); executed: return recode(appendTo, reinterpret_cast<const ushort *>(begin), reinterpret_cast<const ushort *>(end), encoding, actionTable, false); Execution Count:27940 | 27940 |
599 | } | - |
600 | | - |
601 | QString qt_urlRecodeByteArray(const QByteArray &ba) | - |
602 | { | - |
603 | if (ba.isNull()) evaluated: ba.isNull() yes Evaluation Count:2 | yes Evaluation Count:35 |
| 2-35 |
604 | return QString(); executed: return QString(); Execution Count:2 | 2 |
605 | | - |
606 | | - |
607 | | - |
608 | const char *in = ba.constData(); | - |
609 | const char *const end = ba.constEnd(); | - |
610 | for ( ; in < end; ++in) { evaluated: in < end yes Evaluation Count:565 | yes Evaluation Count:33 |
| 33-565 |
611 | if (*in & 0x80) evaluated: *in & 0x80 yes Evaluation Count:2 | yes Evaluation Count:563 |
| 2-563 |
612 | break; executed: break; Execution Count:2 | 2 |
613 | } executed: } Execution Count:563 | 563 |
614 | | - |
615 | if (in == end) { evaluated: in == end yes Evaluation Count:33 | yes Evaluation Count:2 |
| 2-33 |
616 | | - |
617 | return QString::fromLatin1(ba, ba.size()); executed: return QString::fromLatin1(ba, ba.size()); Execution Count:33 | 33 |
618 | } | - |
619 | | - |
620 | | - |
621 | QByteArray intermediate = ba; | - |
622 | intermediate.resize(ba.size() * 3 - (in - ba.constData())); | - |
623 | uchar *out = reinterpret_cast<uchar *>(intermediate.data() + (in - ba.constData())); | - |
624 | for ( ; in < end; ++in) { evaluated: in < end yes Evaluation Count:4 | yes Evaluation Count:2 |
| 2-4 |
625 | if (*in & 0x80) { partially evaluated: *in & 0x80 yes Evaluation Count:4 | no Evaluation Count:0 |
| 0-4 |
626 | | - |
627 | *out++ = '%'; | - |
628 | *out++ = encodeNibble(uchar(*in) >> 4); | - |
629 | *out++ = encodeNibble(uchar(*in) & 0xf); | - |
630 | } else { executed: } Execution Count:4 | 4 |
631 | | - |
632 | *out++ = uchar(*in); | - |
633 | } | 0 |
634 | } | - |
635 | | - |
636 | | - |
637 | return QString::fromLatin1(intermediate, out - reinterpret_cast<uchar *>(intermediate.data())); executed: return QString::fromLatin1(intermediate, out - reinterpret_cast<uchar *>(intermediate.data())); Execution Count:2 | 2 |
638 | } | - |
639 | | - |
640 | | - |
641 | | - |
| | |