Line | Source Code | Coverage |
---|
1 | /**************************************************************************** | - |
2 | ** | - |
3 | ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). | - |
4 | ** Contact: http://www.qt-project.org/legal | - |
5 | ** | - |
6 | ** This file is part of the QtCore module of the Qt Toolkit. | - |
7 | ** | - |
8 | ** $QT_BEGIN_LICENSE:LGPL$ | - |
9 | ** Commercial License Usage | - |
10 | ** Licensees holding valid commercial Qt licenses may use this file in | - |
11 | ** accordance with the commercial license agreement provided with the | - |
12 | ** Software or, alternatively, in accordance with the terms contained in | - |
13 | ** a written agreement between you and Digia. For licensing terms and | - |
14 | ** conditions see http://qt.digia.com/licensing. For further information | - |
15 | ** use the contact form at http://qt.digia.com/contact-us. | - |
16 | ** | - |
17 | ** GNU Lesser General Public License Usage | - |
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - |
19 | ** General Public License version 2.1 as published by the Free Software | - |
20 | ** Foundation and appearing in the file LICENSE.LGPL included in the | - |
21 | ** packaging of this file. Please review the following information to | - |
22 | ** ensure the GNU Lesser General Public License version 2.1 requirements | - |
23 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - |
24 | ** | - |
25 | ** In addition, as a special exception, Digia gives you certain additional | - |
26 | ** rights. These rights are described in the Digia Qt LGPL Exception | - |
27 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - |
28 | ** | - |
29 | ** GNU General Public License Usage | - |
30 | ** Alternatively, this file may be used under the terms of the GNU | - |
31 | ** General Public License version 3.0 as published by the Free Software | - |
32 | ** Foundation and appearing in the file LICENSE.GPL included in the | - |
33 | ** packaging of this file. Please review the following information to | - |
34 | ** ensure the GNU General Public License version 3.0 requirements will be | - |
35 | ** met: http://www.gnu.org/copyleft/gpl.html. | - |
36 | ** | - |
37 | ** | - |
38 | ** $QT_END_LICENSE$ | - |
39 | ** | - |
40 | ****************************************************************************/ | - |
41 | | - |
42 | #include "qicucodec_p.h" | - |
43 | | - |
44 | #ifndef QT_NO_TEXTCODEC | - |
45 | | - |
46 | #include "qtextcodec_p.h" | - |
47 | #include "qutfcodec_p.h" | - |
48 | #include "qlatincodec_p.h" | - |
49 | #include "qtsciicodec_p.h" | - |
50 | #include "qisciicodec_p.h" | - |
51 | #include "private/qcoreglobaldata_p.h" | - |
52 | #include "qdebug.h" | - |
53 | | - |
54 | #include "unicode/ucnv.h" | - |
55 | | - |
56 | QT_BEGIN_NAMESPACE | - |
57 | | - |
58 | static void qIcuCodecStateFree(QTextCodec::ConverterState *state) | - |
59 | { | - |
60 | ucnv_close(static_cast<UConverter *>(state->d)); executed (the execution status of this line is deduced): ucnv_close_44(static_cast<UConverter *>(state->d)); | - |
61 | } executed: } Execution Count:85171 | 85171 |
62 | | - |
63 | bool qTextCodecNameMatch(const char *n, const char *h) | - |
64 | { | - |
65 | return ucnv_compareNames(n, h) == 0; executed: return ucnv_compareNames_44(n, h) == 0; Execution Count:485712 | 485712 |
66 | } | - |
67 | | - |
68 | /* The list below is generated from http://www.iana.org/assignments/character-sets/ | - |
69 | using the snippet of code below: | - |
70 | | - |
71 | #include <QtCore> | - |
72 | #include <unicode/ucnv.h> | - |
73 | | - |
74 | int main(int argc, char **argv) | - |
75 | { | - |
76 | QCoreApplication app(argc, argv); | - |
77 | | - |
78 | QFile file("character-sets.txt"); | - |
79 | file.open(QFile::ReadOnly); | - |
80 | QByteArray name; | - |
81 | int mib = -1; | - |
82 | QByteArray nameList; | - |
83 | int pos = 0; | - |
84 | while (!file.atEnd()) { | - |
85 | QByteArray s = file.readLine().trimmed(); | - |
86 | if (s.isEmpty()) { | - |
87 | if (mib != -1) { | - |
88 | UErrorCode error = U_ZERO_ERROR; | - |
89 | const char *standard_name = ucnv_getStandardName(name, "MIME", &error); | - |
90 | if (U_FAILURE(error) || !standard_name) { | - |
91 | error = U_ZERO_ERROR; | - |
92 | standard_name = ucnv_getStandardName(name, "IANA", &error); | - |
93 | } | - |
94 | UConverter *conv = ucnv_open(standard_name, &error); | - |
95 | if (!U_FAILURE(error) && conv && standard_name) { | - |
96 | ucnv_close(conv); | - |
97 | printf(" { %d, %d },\n", mib, pos); | - |
98 | nameList += "\""; | - |
99 | nameList += standard_name; | - |
100 | nameList += "\\0\"\n"; | - |
101 | pos += strlen(standard_name) + 1; | - |
102 | } | - |
103 | } | - |
104 | name = QByteArray(); | - |
105 | mib = -1; | - |
106 | } | - |
107 | if (s.startsWith("Name: ")) { | - |
108 | name = s.mid(5).trimmed(); | - |
109 | if (name.indexOf(' ') > 0) | - |
110 | name = name.left(name.indexOf(' ')); | - |
111 | } | - |
112 | if (s.startsWith("MIBenum:")) | - |
113 | mib = s.mid(8).trimmed().toInt(); | - |
114 | if (s.startsWith("Alias:") && s.contains("MIME")) { | - |
115 | name = s.mid(6).trimmed(); | - |
116 | name = name.left(name.indexOf(' ')).trimmed(); | - |
117 | } | - |
118 | } | - |
119 | qDebug() << nameList; | - |
120 | } | - |
121 | */ | - |
122 | | - |
123 | struct MibToName { | - |
124 | short mib; | - |
125 | short index; | - |
126 | }; | - |
127 | | - |
128 | static MibToName mibToName[] = { | - |
129 | { 3, 0 }, | - |
130 | { 4, 9 }, | - |
131 | { 5, 20 }, | - |
132 | { 6, 31 }, | - |
133 | { 7, 42 }, | - |
134 | { 8, 53 }, | - |
135 | { 9, 64 }, | - |
136 | { 10, 75 }, | - |
137 | { 11, 86 }, | - |
138 | { 12, 97 }, | - |
139 | { 13, 108 }, | - |
140 | { 16, 120 }, | - |
141 | { 17, 134 }, | - |
142 | { 18, 144 }, | - |
143 | { 30, 151 }, | - |
144 | { 36, 160 }, | - |
145 | { 37, 167 }, | - |
146 | { 38, 179 }, | - |
147 | { 39, 186 }, | - |
148 | { 40, 198 }, | - |
149 | { 57, 212 }, | - |
150 | { 81, 223 }, | - |
151 | { 82, 234 }, | - |
152 | { 84, 245 }, | - |
153 | { 85, 256 }, | - |
154 | { 104, 267 }, | - |
155 | { 105, 279 }, | - |
156 | { 106, 295 }, | - |
157 | { 109, 301 }, | - |
158 | { 110, 313 }, | - |
159 | { 111, 325 }, | - |
160 | { 113, 337 }, | - |
161 | { 114, 341 }, | - |
162 | { 1000, 349 }, | - |
163 | { 1001, 356 }, | - |
164 | { 1011, 363 }, | - |
165 | { 1012, 368 }, | - |
166 | { 1013, 374 }, | - |
167 | { 1014, 383 }, | - |
168 | { 1015, 392 }, | - |
169 | { 1016, 399 }, | - |
170 | { 1017, 406 }, | - |
171 | { 1018, 413 }, | - |
172 | { 1019, 422 }, | - |
173 | { 1020, 431 }, | - |
174 | { 2004, 438 }, | - |
175 | { 2005, 448 }, | - |
176 | { 2009, 472 }, | - |
177 | { 2013, 479 }, | - |
178 | { 2016, 486 }, | - |
179 | { 2024, 495 }, | - |
180 | { 2025, 505 }, | - |
181 | { 2026, 512 }, | - |
182 | { 2027, 517 }, | - |
183 | { 2028, 527 }, | - |
184 | { 2030, 534 }, | - |
185 | { 2033, 541 }, | - |
186 | { 2034, 548 }, | - |
187 | { 2035, 555 }, | - |
188 | { 2037, 562 }, | - |
189 | { 2038, 569 }, | - |
190 | { 2039, 576 }, | - |
191 | { 2040, 583 }, | - |
192 | { 2041, 590 }, | - |
193 | { 2043, 597 }, | - |
194 | { 2011, 604 }, | - |
195 | { 2044, 611 }, | - |
196 | { 2045, 618 }, | - |
197 | { 2010, 624 }, | - |
198 | { 2046, 631 }, | - |
199 | { 2047, 638 }, | - |
200 | { 2048, 645 }, | - |
201 | { 2049, 652 }, | - |
202 | { 2050, 659 }, | - |
203 | { 2051, 666 }, | - |
204 | { 2052, 673 }, | - |
205 | { 2053, 680 }, | - |
206 | { 2054, 687 }, | - |
207 | { 2055, 694 }, | - |
208 | { 2056, 701 }, | - |
209 | { 2062, 708 }, | - |
210 | { 2063, 715 }, | - |
211 | { 2084, 723 }, | - |
212 | { 2085, 730 }, | - |
213 | { 2086, 741 }, | - |
214 | { 2087, 748 }, | - |
215 | { 2088, 755 }, | - |
216 | { 2089, 762 }, | - |
217 | { 2091, 771 }, | - |
218 | { 2092, 780 }, | - |
219 | { 2093, 789 }, | - |
220 | { 2094, 798 }, | - |
221 | { 2095, 807 }, | - |
222 | { 2096, 816 }, | - |
223 | { 2097, 825 }, | - |
224 | { 2098, 834 }, | - |
225 | { 2099, 843 }, | - |
226 | { 2100, 852 }, | - |
227 | { 2101, 861 }, | - |
228 | { 2102, 872 }, | - |
229 | { 2250, 880 }, | - |
230 | { 2251, 893 }, | - |
231 | { 2252, 906 }, | - |
232 | { 2253, 919 }, | - |
233 | { 2254, 932 }, | - |
234 | { 2255, 945 }, | - |
235 | { 2256, 958 }, | - |
236 | { 2257, 971 }, | - |
237 | { 2258, 984 }, | - |
238 | { 2259, 997 }, | - |
239 | }; | - |
240 | int mibToNameSize = sizeof(mibToName)/sizeof(MibToName); | - |
241 | | - |
242 | static const char mibToNameTable[] = | - |
243 | "US-ASCII\0" | - |
244 | "ISO-8859-1\0" | - |
245 | "ISO-8859-2\0" | - |
246 | "ISO-8859-3\0" | - |
247 | "ISO-8859-4\0" | - |
248 | "ISO-8859-5\0" | - |
249 | "ISO-8859-6\0" | - |
250 | "ISO-8859-7\0" | - |
251 | "ISO-8859-8\0" | - |
252 | "ISO-8859-9\0" | - |
253 | "ISO-8859-10\0" | - |
254 | "ISO-2022-JP-1\0" | - |
255 | "Shift_JIS\0" | - |
256 | "EUC-JP\0" | - |
257 | "US-ASCII\0" | - |
258 | "EUC-KR\0" | - |
259 | "ISO-2022-KR\0" | - |
260 | "EUC-KR\0" | - |
261 | "ISO-2022-JP\0" | - |
262 | "ISO-2022-JP-2\0" | - |
263 | "GB_2312-80\0" | - |
264 | "ISO-8859-6\0" | - |
265 | "ISO-8859-6\0" | - |
266 | "ISO-8859-8\0" | - |
267 | "ISO-8859-8\0" | - |
268 | "ISO-2022-CN\0" | - |
269 | "ISO-2022-CN-EXT\0" | - |
270 | "UTF-8\0" | - |
271 | "ISO-8859-13\0" | - |
272 | "ISO-8859-14\0" | - |
273 | "ISO-8859-15\0" | - |
274 | "GBK\0" | - |
275 | "GB18030\0" | - |
276 | "UTF-16\0" | - |
277 | "UTF-32\0" | - |
278 | "SCSU\0" | - |
279 | "UTF-7\0" | - |
280 | "UTF-16BE\0" | - |
281 | "UTF-16LE\0" | - |
282 | "UTF-16\0" | - |
283 | "CESU-8\0" | - |
284 | "UTF-32\0" | - |
285 | "UTF-32BE\0" | - |
286 | "UTF-32LE\0" | - |
287 | "BOCU-1\0" | - |
288 | "hp-roman8\0" | - |
289 | "Adobe-Standard-Encoding\0" | - |
290 | "IBM850\0" | - |
291 | "IBM862\0" | - |
292 | "IBM-Thai\0" | - |
293 | "Shift_JIS\0" | - |
294 | "GB2312\0" | - |
295 | "Big5\0" | - |
296 | "macintosh\0" | - |
297 | "IBM037\0" | - |
298 | "IBM273\0" | - |
299 | "IBM277\0" | - |
300 | "IBM278\0" | - |
301 | "IBM280\0" | - |
302 | "IBM284\0" | - |
303 | "IBM285\0" | - |
304 | "IBM290\0" | - |
305 | "IBM297\0" | - |
306 | "IBM420\0" | - |
307 | "IBM424\0" | - |
308 | "IBM437\0" | - |
309 | "IBM500\0" | - |
310 | "cp851\0" | - |
311 | "IBM852\0" | - |
312 | "IBM855\0" | - |
313 | "IBM857\0" | - |
314 | "IBM860\0" | - |
315 | "IBM861\0" | - |
316 | "IBM863\0" | - |
317 | "IBM864\0" | - |
318 | "IBM865\0" | - |
319 | "IBM868\0" | - |
320 | "IBM869\0" | - |
321 | "IBM870\0" | - |
322 | "IBM871\0" | - |
323 | "IBM918\0" | - |
324 | "IBM1026\0" | - |
325 | "KOI8-R\0" | - |
326 | "HZ-GB-2312\0" | - |
327 | "IBM866\0" | - |
328 | "IBM775\0" | - |
329 | "KOI8-U\0" | - |
330 | "IBM00858\0" | - |
331 | "IBM01140\0" | - |
332 | "IBM01141\0" | - |
333 | "IBM01142\0" | - |
334 | "IBM01143\0" | - |
335 | "IBM01144\0" | - |
336 | "IBM01145\0" | - |
337 | "IBM01146\0" | - |
338 | "IBM01147\0" | - |
339 | "IBM01148\0" | - |
340 | "IBM01149\0" | - |
341 | "Big5-HKSCS\0" | - |
342 | "IBM1047\0" | - |
343 | "windows-1250\0" | - |
344 | "windows-1251\0" | - |
345 | "windows-1252\0" | - |
346 | "windows-1253\0" | - |
347 | "windows-1254\0" | - |
348 | "windows-1255\0" | - |
349 | "windows-1256\0" | - |
350 | "windows-1257\0" | - |
351 | "windows-1258\0" | - |
352 | "TIS-620\0"; | - |
353 | | - |
354 | static QTextCodec *loadQtCodec(const char *name) | - |
355 | { | - |
356 | if (!strcmp(name, "UTF-8")) evaluated: !strcmp(name, "UTF-8") yes Evaluation Count:116 | yes Evaluation Count:150 |
| 116-150 |
357 | return new QUtf8Codec; executed: return new QUtf8Codec; Execution Count:116 | 116 |
358 | if (!strcmp(name, "UTF-16")) evaluated: !strcmp(name, "UTF-16") yes Evaluation Count:7 | yes Evaluation Count:143 |
| 7-143 |
359 | return new QUtf16Codec; executed: return new QUtf16Codec; Execution Count:7 | 7 |
360 | if (!strcmp(name, "ISO-8859-1")) evaluated: !strcmp(name, "ISO-8859-1") yes Evaluation Count:5 | yes Evaluation Count:138 |
| 5-138 |
361 | return new QLatin1Codec; executed: return new QLatin1Codec; Execution Count:5 | 5 |
362 | if (!strcmp(name, "UTF-16BE")) evaluated: !strcmp(name, "UTF-16BE") yes Evaluation Count:4 | yes Evaluation Count:134 |
| 4-134 |
363 | return new QUtf16BECodec; executed: return new QUtf16BECodec; Execution Count:4 | 4 |
364 | if (!strcmp(name, "UTF-16LE")) evaluated: !strcmp(name, "UTF-16LE") yes Evaluation Count:5 | yes Evaluation Count:129 |
| 5-129 |
365 | return new QUtf16LECodec; executed: return new QUtf16LECodec; Execution Count:5 | 5 |
366 | if (!strcmp(name, "UTF-32")) evaluated: !strcmp(name, "UTF-32") yes Evaluation Count:2 | yes Evaluation Count:127 |
| 2-127 |
367 | return new QUtf32Codec; executed: return new QUtf32Codec; Execution Count:2 | 2 |
368 | if (!strcmp(name, "UTF-32BE")) evaluated: !strcmp(name, "UTF-32BE") yes Evaluation Count:2 | yes Evaluation Count:125 |
| 2-125 |
369 | return new QUtf32BECodec; executed: return new QUtf32BECodec; Execution Count:2 | 2 |
370 | if (!strcmp(name, "UTF-32LE")) evaluated: !strcmp(name, "UTF-32LE") yes Evaluation Count:3 | yes Evaluation Count:122 |
| 3-122 |
371 | return new QUtf32LECodec; executed: return new QUtf32LECodec; Execution Count:3 | 3 |
372 | #ifndef QT_NO_CODECS | - |
373 | if (!strcmp(name, "TSCII")) evaluated: !strcmp(name, "TSCII") yes Evaluation Count:1 | yes Evaluation Count:121 |
| 1-121 |
374 | return new QTsciiCodec; executed: return new QTsciiCodec; Execution Count:1 | 1 |
375 | if (!qstrnicmp(name, "iscii", 5)) evaluated: !qstrnicmp(name, "iscii", 5) yes Evaluation Count:9 | yes Evaluation Count:112 |
| 9-112 |
376 | return QIsciiCodec::create(name); executed: return QIsciiCodec::create(name); Execution Count:9 | 9 |
377 | #endif | - |
378 | | - |
379 | return 0; executed: return 0; Execution Count:112 | 112 |
380 | } | - |
381 | | - |
382 | /// \threadsafe | - |
383 | QList<QByteArray> QIcuCodec::availableCodecs() | - |
384 | { | - |
385 | QList<QByteArray> codecs; executed (the execution status of this line is deduced): QList<QByteArray> codecs; | - |
386 | int n = ucnv_countAvailable(); executed (the execution status of this line is deduced): int n = ucnv_countAvailable_44(); | - |
387 | for (int i = 0; i < n; ++i) { evaluated: i < n yes Evaluation Count:450 | yes Evaluation Count:2 |
| 2-450 |
388 | const char *name = ucnv_getAvailableName(i); executed (the execution status of this line is deduced): const char *name = ucnv_getAvailableName_44(i); | - |
389 | | - |
390 | UErrorCode error = U_ZERO_ERROR; executed (the execution status of this line is deduced): UErrorCode error = U_ZERO_ERROR; | - |
391 | const char *standardName = ucnv_getStandardName(name, "MIME", &error); executed (the execution status of this line is deduced): const char *standardName = ucnv_getStandardName_44(name, "MIME", &error); | - |
392 | if (U_FAILURE(error) || !standardName) { partially evaluated: U_FAILURE(error) no Evaluation Count:0 | yes Evaluation Count:450 |
evaluated: !standardName yes Evaluation Count:352 | yes Evaluation Count:98 |
| 0-450 |
393 | error = U_ZERO_ERROR; executed (the execution status of this line is deduced): error = U_ZERO_ERROR; | - |
394 | standardName = ucnv_getStandardName(name, "IANA", &error); executed (the execution status of this line is deduced): standardName = ucnv_getStandardName_44(name, "IANA", &error); | - |
395 | } executed: } Execution Count:352 | 352 |
396 | if (U_FAILURE(error)) partially evaluated: U_FAILURE(error) no Evaluation Count:0 | yes Evaluation Count:450 |
| 0-450 |
397 | continue; never executed: continue; | 0 |
398 | | - |
399 | error = U_ZERO_ERROR; executed (the execution status of this line is deduced): error = U_ZERO_ERROR; | - |
400 | int ac = ucnv_countAliases(standardName, &error); executed (the execution status of this line is deduced): int ac = ucnv_countAliases_44(standardName, &error); | - |
401 | if (U_FAILURE(error)) evaluated: U_FAILURE(error) yes Evaluation Count:238 | yes Evaluation Count:212 |
| 212-238 |
402 | continue; executed: continue; Execution Count:238 | 238 |
403 | for (int j = 0; j < ac; ++j) { evaluated: j < ac yes Evaluation Count:1542 | yes Evaluation Count:212 |
| 212-1542 |
404 | error = U_ZERO_ERROR; executed (the execution status of this line is deduced): error = U_ZERO_ERROR; | - |
405 | const char *alias = ucnv_getAlias(standardName, j, &error); executed (the execution status of this line is deduced): const char *alias = ucnv_getAlias_44(standardName, j, &error); | - |
406 | if (!U_SUCCESS(error)) partially evaluated: !U_SUCCESS(error) no Evaluation Count:0 | yes Evaluation Count:1542 |
| 0-1542 |
407 | continue; never executed: continue; | 0 |
408 | codecs += alias; executed (the execution status of this line is deduced): codecs += alias; | - |
409 | } executed: } Execution Count:1542 | 1542 |
410 | } executed: } Execution Count:212 | 212 |
411 | | - |
412 | // handled by Qt and not in ICU: | - |
413 | codecs += "TSCII"; executed (the execution status of this line is deduced): codecs += "TSCII"; | - |
414 | | - |
415 | return codecs; executed: return codecs; Execution Count:2 | 2 |
416 | } | - |
417 | | - |
418 | /// \threadsafe | - |
419 | QList<int> QIcuCodec::availableMibs() | - |
420 | { | - |
421 | QList<int> mibs; executed (the execution status of this line is deduced): QList<int> mibs; | - |
422 | for (int i = 0; i < mibToNameSize; ++i) evaluated: i < mibToNameSize yes Evaluation Count:220 | yes Evaluation Count:2 |
| 2-220 |
423 | mibs += mibToName[i].mib; executed: mibs += mibToName[i].mib; Execution Count:220 | 220 |
424 | | - |
425 | // handled by Qt and not in ICU: | - |
426 | mibs += 2107; // TSCII executed (the execution status of this line is deduced): mibs += 2107; | - |
427 | | - |
428 | return mibs; executed: return mibs; Execution Count:2 | 2 |
429 | } | - |
430 | | - |
431 | QTextCodec *QIcuCodec::defaultCodecUnlocked() | - |
432 | { | - |
433 | QCoreGlobalData *globalData = QCoreGlobalData::instance(); executed (the execution status of this line is deduced): QCoreGlobalData *globalData = QCoreGlobalData::instance(); | - |
434 | if (!globalData) partially evaluated: !globalData no Evaluation Count:0 | yes Evaluation Count:126 |
| 0-126 |
435 | return 0; never executed: return 0; | 0 |
436 | QTextCodec *c = globalData->codecForLocale.loadAcquire(); executed (the execution status of this line is deduced): QTextCodec *c = globalData->codecForLocale.loadAcquire(); | - |
437 | if (c) evaluated: c yes Evaluation Count:10 | yes Evaluation Count:116 |
| 10-116 |
438 | return c; executed: return c; Execution Count:10 | 10 |
439 | | - |
440 | #if defined(QT_LOCALE_IS_UTF8) | - |
441 | const char *name = "UTF-8"; | - |
442 | #else | - |
443 | const char *name = ucnv_getDefaultName(); executed (the execution status of this line is deduced): const char *name = ucnv_getDefaultName_44(); | - |
444 | #endif | - |
445 | c = codecForNameUnlocked(name); executed (the execution status of this line is deduced): c = codecForNameUnlocked(name); | - |
446 | globalData->codecForLocale.storeRelease(c); executed (the execution status of this line is deduced): globalData->codecForLocale.storeRelease(c); | - |
447 | return c; executed: return c; Execution Count:116 | 116 |
448 | } | - |
449 | | - |
450 | | - |
451 | QTextCodec *QIcuCodec::codecForNameUnlocked(const char *name) | - |
452 | { | - |
453 | // backwards compatibility with Qt 4.x | - |
454 | if (!qstrcmp(name, "CP949")) evaluated: !qstrcmp(name, "CP949") yes Evaluation Count:1 | yes Evaluation Count:11247 |
| 1-11247 |
455 | name = "windows-949"; executed: name = "windows-949"; Execution Count:1 | 1 |
456 | // this one is broken data in ICU 4.4, and can't be resolved even though it's an alias to tis-620 | - |
457 | if (!qstrcmp(name, "windows-874-2000")) evaluated: !qstrcmp(name, "windows-874-2000") yes Evaluation Count:7 | yes Evaluation Count:11241 |
| 7-11241 |
458 | name = "TIS-620"; executed: name = "TIS-620"; Execution Count:7 | 7 |
459 | | - |
460 | UErrorCode error = U_ZERO_ERROR; executed (the execution status of this line is deduced): UErrorCode error = U_ZERO_ERROR; | - |
461 | // MIME gives better default names | - |
462 | const char *standardName = ucnv_getStandardName(name, "MIME", &error); executed (the execution status of this line is deduced): const char *standardName = ucnv_getStandardName_44(name, "MIME", &error); | - |
463 | if (U_FAILURE(error) || !standardName) { evaluated: U_FAILURE(error) yes Evaluation Count:1 | yes Evaluation Count:11247 |
evaluated: !standardName yes Evaluation Count:3469 | yes Evaluation Count:7778 |
| 1-11247 |
464 | error = U_ZERO_ERROR; executed (the execution status of this line is deduced): error = U_ZERO_ERROR; | - |
465 | standardName = ucnv_getStandardName(name, "IANA", &error); executed (the execution status of this line is deduced): standardName = ucnv_getStandardName_44(name, "IANA", &error); | - |
466 | } executed: } Execution Count:3470 | 3470 |
467 | bool qt_only = false; executed (the execution status of this line is deduced): bool qt_only = false; | - |
468 | if (U_FAILURE(error) || !standardName) { evaluated: U_FAILURE(error) yes Evaluation Count:1 | yes Evaluation Count:11247 |
evaluated: !standardName yes Evaluation Count:88 | yes Evaluation Count:11159 |
| 1-11247 |
469 | standardName = name; executed (the execution status of this line is deduced): standardName = name; | - |
470 | qt_only = true; executed (the execution status of this line is deduced): qt_only = true; | - |
471 | } else { executed: } Execution Count:89 | 89 |
472 | // correct some issues where the ICU data set contains duplicated entries. | - |
473 | // Where this happens it's because one data set is a subset of another. We | - |
474 | // always use the larger data set. | - |
475 | | - |
476 | if (qstrcmp(standardName, "GB2312") == 0 || qstrcmp(standardName, "GB_2312-80") == 0) evaluated: qstrcmp(standardName, "GB2312") == 0 yes Evaluation Count:32 | yes Evaluation Count:11127 |
evaluated: qstrcmp(standardName, "GB_2312-80") == 0 yes Evaluation Count:25 | yes Evaluation Count:11102 |
| 25-11127 |
477 | standardName = "GBK"; executed: standardName = "GBK"; Execution Count:57 | 57 |
478 | else if (qstrcmp(standardName, "KSC_5601") == 0 || qstrcmp(standardName, "EUC-KR") == 0 || qstrcmp(standardName, "cp1363") == 0) partially evaluated: qstrcmp(standardName, "KSC_5601") == 0 no Evaluation Count:0 | yes Evaluation Count:11102 |
evaluated: qstrcmp(standardName, "EUC-KR") == 0 yes Evaluation Count:99 | yes Evaluation Count:11003 |
evaluated: qstrcmp(standardName, "cp1363") == 0 yes Evaluation Count:157 | yes Evaluation Count:10846 |
| 0-11102 |
479 | standardName = "windows-949"; executed: standardName = "windows-949"; Execution Count:256 | 256 |
480 | } | - |
481 | | - |
482 | QCoreGlobalData *globalData = QCoreGlobalData::instance(); executed (the execution status of this line is deduced): QCoreGlobalData *globalData = QCoreGlobalData::instance(); | - |
483 | QTextCodecCache *cache = &globalData->codecCache; executed (the execution status of this line is deduced): QTextCodecCache *cache = &globalData->codecCache; | - |
484 | | - |
485 | QTextCodec *codec; executed (the execution status of this line is deduced): QTextCodec *codec; | - |
486 | if (cache) { partially evaluated: cache yes Evaluation Count:11248 | no Evaluation Count:0 |
| 0-11248 |
487 | codec = cache->value(standardName); executed (the execution status of this line is deduced): codec = cache->value(standardName); | - |
488 | if (codec) evaluated: codec yes Evaluation Count:10950 | yes Evaluation Count:298 |
| 298-10950 |
489 | return codec; executed: return codec; Execution Count:10950 | 10950 |
490 | } executed: } Execution Count:298 | 298 |
491 | | - |
492 | for (int i = 0; i < globalData->allCodecs.size(); ++i) { evaluated: i < globalData->allCodecs.size() yes Evaluation Count:7642 | yes Evaluation Count:266 |
| 266-7642 |
493 | QTextCodec *cursor = globalData->allCodecs.at(i); executed (the execution status of this line is deduced): QTextCodec *cursor = globalData->allCodecs.at(i); | - |
494 | if (qTextCodecNameMatch(cursor->name(), standardName)) { evaluated: qTextCodecNameMatch(cursor->name(), standardName) yes Evaluation Count:28 | yes Evaluation Count:7614 |
| 28-7614 |
495 | if (cache) partially evaluated: cache yes Evaluation Count:28 | no Evaluation Count:0 |
| 0-28 |
496 | cache->insert(standardName, cursor); executed: cache->insert(standardName, cursor); Execution Count:28 | 28 |
497 | return cursor; executed: return cursor; Execution Count:28 | 28 |
498 | } | - |
499 | QList<QByteArray> aliases = cursor->aliases(); executed (the execution status of this line is deduced): QList<QByteArray> aliases = cursor->aliases(); | - |
500 | for (int y = 0; y < aliases.size(); ++y) evaluated: y < aliases.size() yes Evaluation Count:40250 | yes Evaluation Count:7610 |
| 7610-40250 |
501 | if (qTextCodecNameMatch(aliases.at(y), standardName)) { evaluated: qTextCodecNameMatch(aliases.at(y), standardName) yes Evaluation Count:4 | yes Evaluation Count:40246 |
| 4-40246 |
502 | if (cache) partially evaluated: cache yes Evaluation Count:4 | no Evaluation Count:0 |
| 0-4 |
503 | cache->insert(standardName, cursor); executed: cache->insert(standardName, cursor); Execution Count:4 | 4 |
504 | return cursor; executed: return cursor; Execution Count:4 | 4 |
505 | } | - |
506 | } executed: } Execution Count:7610 | 7610 |
507 | | - |
508 | QTextCodec *c = loadQtCodec(standardName); executed (the execution status of this line is deduced): QTextCodec *c = loadQtCodec(standardName); | - |
509 | if (c) evaluated: c yes Evaluation Count:154 | yes Evaluation Count:112 |
| 112-154 |
510 | return c; executed: return c; Execution Count:154 | 154 |
511 | | - |
512 | if (qt_only) evaluated: qt_only yes Evaluation Count:11 | yes Evaluation Count:101 |
| 11-101 |
513 | return 0; executed: return 0; Execution Count:11 | 11 |
514 | | - |
515 | // check whether there is really a converter for the name available. | - |
516 | UConverter *conv = ucnv_open(standardName, &error); executed (the execution status of this line is deduced): UConverter *conv = ucnv_open_44(standardName, &error); | - |
517 | if (!conv) { partially evaluated: !conv no Evaluation Count:0 | yes Evaluation Count:101 |
| 0-101 |
518 | qDebug() << "codecForName: ucnv_open failed" << standardName << u_errorName(error); never executed (the execution status of this line is deduced): QMessageLogger("codecs/qicucodec.cpp", 518, __PRETTY_FUNCTION__).debug() << "codecForName: ucnv_open failed" << standardName << u_errorName_44(error); | - |
519 | return 0; never executed: return 0; | 0 |
520 | } | - |
521 | //qDebug() << "QIcuCodec: Standard name for " << name << "is" << standardName; | - |
522 | ucnv_close(conv); executed (the execution status of this line is deduced): ucnv_close_44(conv); | - |
523 | | - |
524 | | - |
525 | c = new QIcuCodec(standardName); executed (the execution status of this line is deduced): c = new QIcuCodec(standardName); | - |
526 | if (cache) partially evaluated: cache yes Evaluation Count:101 | no Evaluation Count:0 |
| 0-101 |
527 | cache->insert(standardName, c); executed: cache->insert(standardName, c); Execution Count:101 | 101 |
528 | return c; executed: return c; Execution Count:101 | 101 |
529 | } | - |
530 | | - |
531 | | - |
532 | QTextCodec *QIcuCodec::codecForMibUnlocked(int mib) | - |
533 | { | - |
534 | for (int i = 0; i < mibToNameSize; ++i) { partially evaluated: i < mibToNameSize yes Evaluation Count:903 | no Evaluation Count:0 |
| 0-903 |
535 | if (mibToName[i].mib == mib) evaluated: mibToName[i].mib == mib yes Evaluation Count:27 | yes Evaluation Count:876 |
| 27-876 |
536 | return codecForNameUnlocked(mibToNameTable + mibToName[i].index); executed: return codecForNameUnlocked(mibToNameTable + mibToName[i].index); Execution Count:27 | 27 |
537 | } executed: } Execution Count:876 | 876 |
538 | | - |
539 | if (mib == 2107) never evaluated: mib == 2107 | 0 |
540 | return codecForNameUnlocked("TSCII"); never executed: return codecForNameUnlocked("TSCII"); | 0 |
541 | | - |
542 | return 0; never executed: return 0; | 0 |
543 | } | - |
544 | | - |
545 | | - |
546 | QIcuCodec::QIcuCodec(const char *name) | - |
547 | : m_name(name) | - |
548 | { | - |
549 | } executed: } Execution Count:101 | 101 |
550 | | - |
551 | QIcuCodec::~QIcuCodec() | - |
552 | { | - |
553 | } | - |
554 | | - |
555 | UConverter *QIcuCodec::getConverter(QTextCodec::ConverterState *state) const | - |
556 | { | - |
557 | UConverter *conv = 0; executed (the execution status of this line is deduced): UConverter *conv = 0; | - |
558 | if (state) { evaluated: state yes Evaluation Count:88922 | yes Evaluation Count:6850 |
| 6850-88922 |
559 | if (!state->d) { evaluated: !state->d yes Evaluation Count:85171 | yes Evaluation Count:3751 |
| 3751-85171 |
560 | // first time | - |
561 | state->flags |= QTextCodec::FreeFunction; executed (the execution status of this line is deduced): state->flags |= QTextCodec::FreeFunction; | - |
562 | QTextCodecUnalignedPointer::encode(state->state_data, qIcuCodecStateFree); executed (the execution status of this line is deduced): QTextCodecUnalignedPointer::encode(state->state_data, qIcuCodecStateFree); | - |
563 | UErrorCode error = U_ZERO_ERROR; executed (the execution status of this line is deduced): UErrorCode error = U_ZERO_ERROR; | - |
564 | state->d = ucnv_open(m_name, &error); executed (the execution status of this line is deduced): state->d = ucnv_open_44(m_name, &error); | - |
565 | ucnv_setSubstChars(static_cast<UConverter *>(state->d), executed (the execution status of this line is deduced): ucnv_setSubstChars_44(static_cast<UConverter *>(state->d), | - |
566 | state->flags & QTextCodec::ConvertInvalidToNull ? "\0" : "?", 1, &error); executed (the execution status of this line is deduced): state->flags & QTextCodec::ConvertInvalidToNull ? "\0" : "?", 1, &error); | - |
567 | if (U_FAILURE(error)) partially evaluated: U_FAILURE(error) no Evaluation Count:0 | yes Evaluation Count:85171 |
| 0-85171 |
568 | qDebug() << "getConverter(state) ucnv_open failed" << m_name << u_errorName(error); never executed: QMessageLogger("codecs/qicucodec.cpp", 568, __PRETTY_FUNCTION__).debug() << "getConverter(state) ucnv_open failed" << m_name << u_errorName_44(error); | 0 |
569 | } executed: } Execution Count:85171 | 85171 |
570 | conv = static_cast<UConverter *>(state->d); executed (the execution status of this line is deduced): conv = static_cast<UConverter *>(state->d); | - |
571 | } executed: } Execution Count:88922 | 88922 |
572 | if (!conv) { evaluated: !conv yes Evaluation Count:6850 | yes Evaluation Count:88922 |
| 6850-88922 |
573 | // stateless conversion | - |
574 | UErrorCode error = U_ZERO_ERROR; executed (the execution status of this line is deduced): UErrorCode error = U_ZERO_ERROR; | - |
575 | conv = ucnv_open(m_name, &error); executed (the execution status of this line is deduced): conv = ucnv_open_44(m_name, &error); | - |
576 | ucnv_setSubstChars(conv, "?", 1, &error); executed (the execution status of this line is deduced): ucnv_setSubstChars_44(conv, "?", 1, &error); | - |
577 | if (U_FAILURE(error)) partially evaluated: U_FAILURE(error) no Evaluation Count:0 | yes Evaluation Count:6850 |
| 0-6850 |
578 | qDebug() << "getConverter(no state) ucnv_open failed" << m_name << u_errorName(error); never executed: QMessageLogger("codecs/qicucodec.cpp", 578, __PRETTY_FUNCTION__).debug() << "getConverter(no state) ucnv_open failed" << m_name << u_errorName_44(error); | 0 |
579 | } executed: } Execution Count:6848 | 6848 |
580 | return conv; executed: return conv; Execution Count:95769 | 95769 |
581 | } | - |
582 | | - |
583 | QString QIcuCodec::convertToUnicode(const char *chars, int length, QTextCodec::ConverterState *state) const | - |
584 | { | - |
585 | UConverter *conv = getConverter(state); executed (the execution status of this line is deduced): UConverter *conv = getConverter(state); | - |
586 | | - |
587 | QString string(length + 2, Qt::Uninitialized); executed (the execution status of this line is deduced): QString string(length + 2, Qt::Uninitialized); | - |
588 | | - |
589 | const char *end = chars + length; executed (the execution status of this line is deduced): const char *end = chars + length; | - |
590 | int convertedChars = 0; executed (the execution status of this line is deduced): int convertedChars = 0; | - |
591 | while (1) { partially evaluated: 1 yes Evaluation Count:4865 | no Evaluation Count:0 |
| 0-4865 |
592 | UChar *uc = (UChar *)string.data(); executed (the execution status of this line is deduced): UChar *uc = (UChar *)string.data(); | - |
593 | UChar *ucEnd = uc + string.length(); executed (the execution status of this line is deduced): UChar *ucEnd = uc + string.length(); | - |
594 | uc += convertedChars; executed (the execution status of this line is deduced): uc += convertedChars; | - |
595 | UErrorCode error = U_ZERO_ERROR; executed (the execution status of this line is deduced): UErrorCode error = U_ZERO_ERROR; | - |
596 | ucnv_toUnicode(conv, executed (the execution status of this line is deduced): ucnv_toUnicode_44(conv, | - |
597 | &uc, ucEnd, executed (the execution status of this line is deduced): &uc, ucEnd, | - |
598 | &chars, end, executed (the execution status of this line is deduced): &chars, end, | - |
599 | 0, false, &error); executed (the execution status of this line is deduced): 0, false, &error); | - |
600 | if (!U_SUCCESS(error) && error != U_BUFFER_OVERFLOW_ERROR) { partially evaluated: !U_SUCCESS(error) no Evaluation Count:0 | yes Evaluation Count:4864 |
never evaluated: error != U_BUFFER_OVERFLOW_ERROR | 0-4864 |
601 | qDebug() << "convertToUnicode failed:" << u_errorName(error); never executed (the execution status of this line is deduced): QMessageLogger("codecs/qicucodec.cpp", 601, __PRETTY_FUNCTION__).debug() << "convertToUnicode failed:" << u_errorName_44(error); | - |
602 | break; | 0 |
603 | } | - |
604 | | - |
605 | convertedChars = uc - (UChar *)string.data(); executed (the execution status of this line is deduced): convertedChars = uc - (UChar *)string.data(); | - |
606 | if (chars >= end) partially evaluated: chars >= end yes Evaluation Count:4864 | no Evaluation Count:0 |
| 0-4864 |
607 | break; executed: break; Execution Count:4864 | 4864 |
608 | string.resize(string.length()*2); never executed (the execution status of this line is deduced): string.resize(string.length()*2); | - |
609 | } | 0 |
610 | string.resize(convertedChars); executed (the execution status of this line is deduced): string.resize(convertedChars); | - |
611 | | - |
612 | if (!state) evaluated: !state yes Evaluation Count:3988 | yes Evaluation Count:875 |
| 875-3988 |
613 | ucnv_close(conv); executed: ucnv_close_44(conv); Execution Count:3988 | 3988 |
614 | return string; executed: return string; Execution Count:4866 | 4866 |
615 | } | - |
616 | | - |
617 | | - |
618 | QByteArray QIcuCodec::convertFromUnicode(const QChar *unicode, int length, QTextCodec::ConverterState *state) const | - |
619 | { | - |
620 | UConverter *conv = getConverter(state); executed (the execution status of this line is deduced): UConverter *conv = getConverter(state); | - |
621 | | - |
622 | int requiredLength = UCNV_GET_MAX_BYTES_FOR_STRING(length, ucnv_getMaxCharSize(conv)); executed (the execution status of this line is deduced): int requiredLength = (((int32_t)(length)+10)*(int32_t)(ucnv_getMaxCharSize_44(conv))); | - |
623 | QByteArray string(requiredLength, Qt::Uninitialized); executed (the execution status of this line is deduced): QByteArray string(requiredLength, Qt::Uninitialized); | - |
624 | | - |
625 | const UChar *uc = (const UChar *)unicode; executed (the execution status of this line is deduced): const UChar *uc = (const UChar *)unicode; | - |
626 | const UChar *end = uc + length; executed (the execution status of this line is deduced): const UChar *end = uc + length; | - |
627 | int convertedChars = 0; executed (the execution status of this line is deduced): int convertedChars = 0; | - |
628 | while (1) { partially evaluated: 1 yes Evaluation Count:90908 | no Evaluation Count:0 |
| 0-90908 |
629 | char *ch = (char *)string.data(); executed (the execution status of this line is deduced): char *ch = (char *)string.data(); | - |
630 | char *chEnd = ch + string.length(); executed (the execution status of this line is deduced): char *chEnd = ch + string.length(); | - |
631 | ch += convertedChars; executed (the execution status of this line is deduced): ch += convertedChars; | - |
632 | UErrorCode error = U_ZERO_ERROR; executed (the execution status of this line is deduced): UErrorCode error = U_ZERO_ERROR; | - |
633 | ucnv_fromUnicode(conv, executed (the execution status of this line is deduced): ucnv_fromUnicode_44(conv, | - |
634 | &ch, chEnd, executed (the execution status of this line is deduced): &ch, chEnd, | - |
635 | &uc, end, executed (the execution status of this line is deduced): &uc, end, | - |
636 | 0, false, &error); executed (the execution status of this line is deduced): 0, false, &error); | - |
637 | if (!U_SUCCESS(error)) partially evaluated: !U_SUCCESS(error) no Evaluation Count:0 | yes Evaluation Count:90909 |
| 0-90909 |
638 | qDebug() << "convertFromUnicode failed:" << u_errorName(error); never executed: QMessageLogger("codecs/qicucodec.cpp", 638, __PRETTY_FUNCTION__).debug() << "convertFromUnicode failed:" << u_errorName_44(error); | 0 |
639 | convertedChars = ch - string.data(); executed (the execution status of this line is deduced): convertedChars = ch - string.data(); | - |
640 | if (uc >= end) partially evaluated: uc >= end yes Evaluation Count:90908 | no Evaluation Count:0 |
| 0-90908 |
641 | break; executed: break; Execution Count:90908 | 90908 |
642 | string.resize(string.length()*2); never executed (the execution status of this line is deduced): string.resize(string.length()*2); | - |
643 | } | 0 |
644 | string.resize(convertedChars); executed (the execution status of this line is deduced): string.resize(convertedChars); | - |
645 | | - |
646 | if (!state) evaluated: !state yes Evaluation Count:2861 | yes Evaluation Count:88047 |
| 2861-88047 |
647 | ucnv_close(conv); executed: ucnv_close_44(conv); Execution Count:2861 | 2861 |
648 | | - |
649 | return string; executed: return string; Execution Count:90909 | 90909 |
650 | } | - |
651 | | - |
652 | | - |
653 | QByteArray QIcuCodec::name() const | - |
654 | { | - |
655 | return m_name; executed: return m_name; Execution Count:7145 | 7145 |
656 | } | - |
657 | | - |
658 | | - |
659 | QList<QByteArray> QIcuCodec::aliases() const | - |
660 | { | - |
661 | UErrorCode error = U_ZERO_ERROR; executed (the execution status of this line is deduced): UErrorCode error = U_ZERO_ERROR; | - |
662 | | - |
663 | int n = ucnv_countAliases(m_name, &error); executed (the execution status of this line is deduced): int n = ucnv_countAliases_44(m_name, &error); | - |
664 | | - |
665 | QList<QByteArray> aliases; executed (the execution status of this line is deduced): QList<QByteArray> aliases; | - |
666 | for (int i = 0; i < n; ++i) { evaluated: i < n yes Evaluation Count:51774 | yes Evaluation Count:7129 |
| 7129-51774 |
667 | const char *a = ucnv_getAlias(m_name, i, &error); executed (the execution status of this line is deduced): const char *a = ucnv_getAlias_44(m_name, i, &error); | - |
668 | // skip the canonical name | - |
669 | if (!a || !qstrcmp(a, m_name)) partially evaluated: !a no Evaluation Count:0 | yes Evaluation Count:51774 |
evaluated: !qstrcmp(a, m_name) yes Evaluation Count:7129 | yes Evaluation Count:44645 |
| 0-51774 |
670 | continue; executed: continue; Execution Count:7129 | 7129 |
671 | aliases += a; executed (the execution status of this line is deduced): aliases += a; | - |
672 | } executed: } Execution Count:44645 | 44645 |
673 | | - |
674 | return aliases; executed: return aliases; Execution Count:7129 | 7129 |
675 | } | - |
676 | | - |
677 | | - |
678 | int QIcuCodec::mibEnum() const | - |
679 | { | - |
680 | for (int i = 0; i < mibToNameSize; ++i) { evaluated: i < mibToNameSize yes Evaluation Count:437775 | yes Evaluation Count:335 |
| 335-437775 |
681 | if (qTextCodecNameMatch(m_name, (mibToNameTable + mibToName[i].index))) evaluated: qTextCodecNameMatch(m_name, (mibToNameTable + mibToName[i].index)) yes Evaluation Count:5917 | yes Evaluation Count:431858 |
| 5917-431858 |
682 | return mibToName[i].mib; executed: return mibToName[i].mib; Execution Count:5917 | 5917 |
683 | } executed: } Execution Count:431858 | 431858 |
684 | | - |
685 | return 0; executed: return 0; Execution Count:335 | 335 |
686 | } | - |
687 | | - |
688 | QT_END_NAMESPACE | - |
689 | | - |
690 | #endif // QT_NO_TEXTCODEC | - |
691 | | - |
| | |