codecs/qicucodec.cpp

Source codeSwitch to Preprocessed file
LineSource CodeCoverage
1/**************************************************************************** -
2** -
3** Copyright (C) 2013 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 -
56QT_BEGIN_NAMESPACE -
57 -
58static 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 -
63bool 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:484870
484870
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 -
74int 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 -
123struct MibToName { -
124 short mib; -
125 short index; -
126}; -
127 -
128static 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}; -
240int mibToNameSize = sizeof(mibToName)/sizeof(MibToName); -
241 -
242static 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 -
354static QTextCodec *loadQtCodec(const char *name) -
355{ -
356 if (!strcmp(name, "UTF-8"))
evaluated: !strcmp(name, "UTF-8")
TRUEFALSE
yes
Evaluation Count:117
yes
Evaluation Count:149
117-149
357 return new QUtf8Codec;
executed: return new QUtf8Codec;
Execution Count:117
117
358 if (!strcmp(name, "UTF-16"))
evaluated: !strcmp(name, "UTF-16")
TRUEFALSE
yes
Evaluation Count:7
yes
Evaluation Count:142
7-142
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")
TRUEFALSE
yes
Evaluation Count:5
yes
Evaluation Count:137
5-137
361 return new QLatin1Codec;
executed: return new QLatin1Codec;
Execution Count:5
5
362 if (!strcmp(name, "UTF-16BE"))
evaluated: !strcmp(name, "UTF-16BE")
TRUEFALSE
yes
Evaluation Count:4
yes
Evaluation Count:133
4-133
363 return new QUtf16BECodec;
executed: return new QUtf16BECodec;
Execution Count:4
4
364 if (!strcmp(name, "UTF-16LE"))
evaluated: !strcmp(name, "UTF-16LE")
TRUEFALSE
yes
Evaluation Count:5
yes
Evaluation Count:128
5-128
365 return new QUtf16LECodec;
executed: return new QUtf16LECodec;
Execution Count:5
5
366 if (!strcmp(name, "UTF-32"))
evaluated: !strcmp(name, "UTF-32")
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:126
2-126
367 return new QUtf32Codec;
executed: return new QUtf32Codec;
Execution Count:2
2
368 if (!strcmp(name, "UTF-32BE"))
evaluated: !strcmp(name, "UTF-32BE")
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:124
2-124
369 return new QUtf32BECodec;
executed: return new QUtf32BECodec;
Execution Count:2
2
370 if (!strcmp(name, "UTF-32LE"))
evaluated: !strcmp(name, "UTF-32LE")
TRUEFALSE
yes
Evaluation Count:3
yes
Evaluation Count:121
3-121
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")
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:120
1-120
374 return new QTsciiCodec;
executed: return new QTsciiCodec;
Execution Count:1
1
375 if (!qstrnicmp(name, "iscii", 5))
evaluated: !qstrnicmp(name, "iscii", 5)
TRUEFALSE
yes
Evaluation Count:9
yes
Evaluation Count:111
9-111
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:111
111
380} -
381 -
382/// \threadsafe -
383QList<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
TRUEFALSE
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)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:450
evaluated: !standardName
TRUEFALSE
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)
TRUEFALSE
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)
TRUEFALSE
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
TRUEFALSE
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)
TRUEFALSE
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 -
419QList<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
TRUEFALSE
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 -
431QTextCodec *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
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:127
0-127
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
TRUEFALSE
yes
Evaluation Count:10
yes
Evaluation Count:117
10-117
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:117
117
448} -
449 -
450 -
451QTextCodec *QIcuCodec::codecForNameUnlocked(const char *name) -
452{ -
453 // backwards compatibility with Qt 4.x -
454 if (!qstrcmp(name, "CP949"))
evaluated: !qstrcmp(name, "CP949")
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:11296
1-11296
455 name = "windows-949";
executed: name = "windows-949";
Execution Count:1
1
456 // these are broken data in ICU 4.4, and can't be resolved even though they are aliases to tis-620 -
457 if (!qstrcmp(name, "windows-874-2000")
evaluated: !qstrcmp(name, "windows-874-2000")
TRUEFALSE
yes
Evaluation Count:7
yes
Evaluation Count:11290
7-11290
458 || !qstrcmp(name, "windows-874")
evaluated: !qstrcmp(name, "windows-874")
TRUEFALSE
yes
Evaluation Count:7
yes
Evaluation Count:11283
7-11283
459 || !qstrcmp(name, "MS874")
evaluated: !qstrcmp(name, "MS874")
TRUEFALSE
yes
Evaluation Count:7
yes
Evaluation Count:11276
7-11276
460 || !qstrcmp(name, "x-windows-874"))
partially evaluated: !qstrcmp(name, "x-windows-874")
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:11276
0-11276
461 name = "TIS-620";
executed: name = "TIS-620";
Execution Count:21
21
462 -
463 UErrorCode error = U_ZERO_ERROR;
executed (the execution status of this line is deduced): UErrorCode error = U_ZERO_ERROR;
-
464 // MIME gives better default names -
465 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);
-
466 if (U_FAILURE(error) || !standardName) {
evaluated: U_FAILURE(error)
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:11296
evaluated: !standardName
TRUEFALSE
yes
Evaluation Count:3469
yes
Evaluation Count:7827
1-11296
467 error = U_ZERO_ERROR;
executed (the execution status of this line is deduced): error = U_ZERO_ERROR;
-
468 standardName = ucnv_getStandardName(name, "IANA", &error);
executed (the execution status of this line is deduced): standardName = ucnv_getStandardName_44(name, "IANA", &error);
-
469 }
executed: }
Execution Count:3470
3470
470 bool qt_only = false;
executed (the execution status of this line is deduced): bool qt_only = false;
-
471 if (U_FAILURE(error) || !standardName) {
evaluated: U_FAILURE(error)
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:11296
evaluated: !standardName
TRUEFALSE
yes
Evaluation Count:74
yes
Evaluation Count:11222
1-11296
472 standardName = name;
executed (the execution status of this line is deduced): standardName = name;
-
473 qt_only = true;
executed (the execution status of this line is deduced): qt_only = true;
-
474 } else {
executed: }
Execution Count:75
75
475 // correct some issues where the ICU data set contains duplicated entries. -
476 // Where this happens it's because one data set is a subset of another. We -
477 // always use the larger data set. -
478 -
479 if (qstrcmp(standardName, "GB2312") == 0 || qstrcmp(standardName, "GB_2312-80") == 0)
evaluated: qstrcmp(standardName, "GB2312") == 0
TRUEFALSE
yes
Evaluation Count:32
yes
Evaluation Count:11190
evaluated: qstrcmp(standardName, "GB_2312-80") == 0
TRUEFALSE
yes
Evaluation Count:25
yes
Evaluation Count:11165
25-11190
480 standardName = "GBK";
executed: standardName = "GBK";
Execution Count:57
57
481 else if (qstrcmp(standardName, "KSC_5601") == 0 || qstrcmp(standardName, "EUC-KR") == 0 || qstrcmp(standardName, "cp1363") == 0)
partially evaluated: qstrcmp(standardName, "KSC_5601") == 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:11165
evaluated: qstrcmp(standardName, "EUC-KR") == 0
TRUEFALSE
yes
Evaluation Count:99
yes
Evaluation Count:11066
evaluated: qstrcmp(standardName, "cp1363") == 0
TRUEFALSE
yes
Evaluation Count:157
yes
Evaluation Count:10909
0-11165
482 standardName = "windows-949";
executed: standardName = "windows-949";
Execution Count:256
256
483 } -
484 -
485 QCoreGlobalData *globalData = QCoreGlobalData::instance();
executed (the execution status of this line is deduced): QCoreGlobalData *globalData = QCoreGlobalData::instance();
-
486 QTextCodecCache *cache = &globalData->codecCache;
executed (the execution status of this line is deduced): QTextCodecCache *cache = &globalData->codecCache;
-
487 -
488 QTextCodec *codec;
executed (the execution status of this line is deduced): QTextCodec *codec;
-
489 if (cache) {
partially evaluated: cache
TRUEFALSE
yes
Evaluation Count:11297
no
Evaluation Count:0
0-11297
490 codec = cache->value(standardName);
executed (the execution status of this line is deduced): codec = cache->value(standardName);
-
491 if (codec)
evaluated: codec
TRUEFALSE
yes
Evaluation Count:10998
yes
Evaluation Count:299
299-10998
492 return codec;
executed: return codec;
Execution Count:10998
10998
493 }
executed: }
Execution Count:299
299
494 -
495 for (int i = 0; i < globalData->allCodecs.size(); ++i) {
evaluated: i < globalData->allCodecs.size()
TRUEFALSE
yes
Evaluation Count:7533
yes
Evaluation Count:266
266-7533
496 QTextCodec *cursor = globalData->allCodecs.at(i);
executed (the execution status of this line is deduced): QTextCodec *cursor = globalData->allCodecs.at(i);
-
497 if (qTextCodecNameMatch(cursor->name(), standardName)) {
evaluated: qTextCodecNameMatch(cursor->name(), standardName)
TRUEFALSE
yes
Evaluation Count:31
yes
Evaluation Count:7502
31-7502
498 if (cache)
partially evaluated: cache
TRUEFALSE
yes
Evaluation Count:31
no
Evaluation Count:0
0-31
499 cache->insert(standardName, cursor);
executed: cache->insert(standardName, cursor);
Execution Count:31
31
500 return cursor;
executed: return cursor;
Execution Count:31
31
501 } -
502 QList<QByteArray> aliases = cursor->aliases();
executed (the execution status of this line is deduced): QList<QByteArray> aliases = cursor->aliases();
-
503 for (int y = 0; y < aliases.size(); ++y)
evaluated: y < aliases.size()
TRUEFALSE
yes
Evaluation Count:39694
yes
Evaluation Count:7500
7500-39694
504 if (qTextCodecNameMatch(aliases.at(y), standardName)) {
evaluated: qTextCodecNameMatch(aliases.at(y), standardName)
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:39692
2-39692
505 if (cache)
partially evaluated: cache
TRUEFALSE
yes
Evaluation Count:2
no
Evaluation Count:0
0-2
506 cache->insert(standardName, cursor);
executed: cache->insert(standardName, cursor);
Execution Count:2
2
507 return cursor;
executed: return cursor;
Execution Count:2
2
508 } -
509 }
executed: }
Execution Count:7500
7500
510 -
511 QTextCodec *c = loadQtCodec(standardName);
executed (the execution status of this line is deduced): QTextCodec *c = loadQtCodec(standardName);
-
512 if (c)
evaluated: c
TRUEFALSE
yes
Evaluation Count:155
yes
Evaluation Count:111
111-155
513 return c;
executed: return c;
Execution Count:155
155
514 -
515 if (qt_only)
evaluated: qt_only
TRUEFALSE
yes
Evaluation Count:10
yes
Evaluation Count:101
10-101
516 return 0;
executed: return 0;
Execution Count:10
10
517 -
518 // check whether there is really a converter for the name available. -
519 UConverter *conv = ucnv_open(standardName, &error);
executed (the execution status of this line is deduced): UConverter *conv = ucnv_open_44(standardName, &error);
-
520 if (!conv) {
partially evaluated: !conv
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:101
0-101
521 qDebug() << "codecForName: ucnv_open failed" << standardName << u_errorName(error);
never executed (the execution status of this line is deduced): QMessageLogger("codecs/qicucodec.cpp", 521, __PRETTY_FUNCTION__).debug() << "codecForName: ucnv_open failed" << standardName << u_errorName_44(error);
-
522 return 0;
never executed: return 0;
0
523 } -
524 //qDebug() << "QIcuCodec: Standard name for " << name << "is" << standardName; -
525 ucnv_close(conv);
executed (the execution status of this line is deduced): ucnv_close_44(conv);
-
526 -
527 -
528 c = new QIcuCodec(standardName);
executed (the execution status of this line is deduced): c = new QIcuCodec(standardName);
-
529 if (cache)
partially evaluated: cache
TRUEFALSE
yes
Evaluation Count:101
no
Evaluation Count:0
0-101
530 cache->insert(standardName, c);
executed: cache->insert(standardName, c);
Execution Count:101
101
531 return c;
executed: return c;
Execution Count:101
101
532} -
533 -
534 -
535QTextCodec *QIcuCodec::codecForMibUnlocked(int mib) -
536{ -
537 for (int i = 0; i < mibToNameSize; ++i) {
partially evaluated: i < mibToNameSize
TRUEFALSE
yes
Evaluation Count:903
no
Evaluation Count:0
0-903
538 if (mibToName[i].mib == mib)
evaluated: mibToName[i].mib == mib
TRUEFALSE
yes
Evaluation Count:27
yes
Evaluation Count:876
27-876
539 return codecForNameUnlocked(mibToNameTable + mibToName[i].index);
executed: return codecForNameUnlocked(mibToNameTable + mibToName[i].index);
Execution Count:27
27
540 }
executed: }
Execution Count:876
876
541 -
542 if (mib == 2107)
never evaluated: mib == 2107
0
543 return codecForNameUnlocked("TSCII");
never executed: return codecForNameUnlocked("TSCII");
0
544 -
545 return 0;
never executed: return 0;
0
546} -
547 -
548 -
549QIcuCodec::QIcuCodec(const char *name) -
550 : m_name(name) -
551{ -
552}
executed: }
Execution Count:101
101
553 -
554QIcuCodec::~QIcuCodec() -
555{ -
556} -
557 -
558UConverter *QIcuCodec::getConverter(QTextCodec::ConverterState *state) const -
559{ -
560 UConverter *conv = 0;
executed (the execution status of this line is deduced): UConverter *conv = 0;
-
561 if (state) {
evaluated: state
TRUEFALSE
yes
Evaluation Count:88922
yes
Evaluation Count:6855
6855-88922
562 if (!state->d) {
evaluated: !state->d
TRUEFALSE
yes
Evaluation Count:85171
yes
Evaluation Count:3751
3751-85171
563 // first time -
564 state->flags |= QTextCodec::FreeFunction;
executed (the execution status of this line is deduced): state->flags |= QTextCodec::FreeFunction;
-
565 QTextCodecUnalignedPointer::encode(state->state_data, qIcuCodecStateFree);
executed (the execution status of this line is deduced): QTextCodecUnalignedPointer::encode(state->state_data, qIcuCodecStateFree);
-
566 UErrorCode error = U_ZERO_ERROR;
executed (the execution status of this line is deduced): UErrorCode error = U_ZERO_ERROR;
-
567 state->d = ucnv_open(m_name, &error);
executed (the execution status of this line is deduced): state->d = ucnv_open_44(m_name, &error);
-
568 ucnv_setSubstChars(static_cast<UConverter *>(state->d),
executed (the execution status of this line is deduced): ucnv_setSubstChars_44(static_cast<UConverter *>(state->d),
-
569 state->flags & QTextCodec::ConvertInvalidToNull ? "\0" : "?", 1, &error);
executed (the execution status of this line is deduced): state->flags & QTextCodec::ConvertInvalidToNull ? "\0" : "?", 1, &error);
-
570 if (U_FAILURE(error))
partially evaluated: U_FAILURE(error)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:85171
0-85171
571 qDebug() << "getConverter(state) ucnv_open failed" << m_name << u_errorName(error);
never executed: QMessageLogger("codecs/qicucodec.cpp", 571, __PRETTY_FUNCTION__).debug() << "getConverter(state) ucnv_open failed" << m_name << u_errorName_44(error);
0
572 }
executed: }
Execution Count:85171
85171
573 conv = static_cast<UConverter *>(state->d);
executed (the execution status of this line is deduced): conv = static_cast<UConverter *>(state->d);
-
574 }
executed: }
Execution Count:88922
88922
575 if (!conv) {
evaluated: !conv
TRUEFALSE
yes
Evaluation Count:6856
yes
Evaluation Count:88922
6856-88922
576 // stateless conversion -
577 UErrorCode error = U_ZERO_ERROR;
executed (the execution status of this line is deduced): UErrorCode error = U_ZERO_ERROR;
-
578 conv = ucnv_open(m_name, &error);
executed (the execution status of this line is deduced): conv = ucnv_open_44(m_name, &error);
-
579 ucnv_setSubstChars(conv, "?", 1, &error);
executed (the execution status of this line is deduced): ucnv_setSubstChars_44(conv, "?", 1, &error);
-
580 if (U_FAILURE(error))
partially evaluated: U_FAILURE(error)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:6854
0-6854
581 qDebug() << "getConverter(no state) ucnv_open failed" << m_name << u_errorName(error);
never executed: QMessageLogger("codecs/qicucodec.cpp", 581, __PRETTY_FUNCTION__).debug() << "getConverter(no state) ucnv_open failed" << m_name << u_errorName_44(error);
0
582 }
executed: }
Execution Count:6855
6855
583 return conv;
executed: return conv;
Execution Count:95777
95777
584} -
585 -
586QString QIcuCodec::convertToUnicode(const char *chars, int length, QTextCodec::ConverterState *state) const -
587{ -
588 UConverter *conv = getConverter(state);
executed (the execution status of this line is deduced): UConverter *conv = getConverter(state);
-
589 -
590 QString string(length + 2, Qt::Uninitialized);
executed (the execution status of this line is deduced): QString string(length + 2, Qt::Uninitialized);
-
591 -
592 const char *end = chars + length;
executed (the execution status of this line is deduced): const char *end = chars + length;
-
593 int convertedChars = 0;
executed (the execution status of this line is deduced): int convertedChars = 0;
-
594 while (1) {
partially evaluated: 1
TRUEFALSE
yes
Evaluation Count:4867
no
Evaluation Count:0
0-4867
595 UChar *uc = (UChar *)string.data();
executed (the execution status of this line is deduced): UChar *uc = (UChar *)string.data();
-
596 UChar *ucEnd = uc + string.length();
executed (the execution status of this line is deduced): UChar *ucEnd = uc + string.length();
-
597 uc += convertedChars;
executed (the execution status of this line is deduced): uc += convertedChars;
-
598 UErrorCode error = U_ZERO_ERROR;
executed (the execution status of this line is deduced): UErrorCode error = U_ZERO_ERROR;
-
599 ucnv_toUnicode(conv,
executed (the execution status of this line is deduced): ucnv_toUnicode_44(conv,
-
600 &uc, ucEnd,
executed (the execution status of this line is deduced): &uc, ucEnd,
-
601 &chars, end,
executed (the execution status of this line is deduced): &chars, end,
-
602 0, false, &error);
executed (the execution status of this line is deduced): 0, false, &error);
-
603 if (!U_SUCCESS(error) && error != U_BUFFER_OVERFLOW_ERROR) {
partially evaluated: !U_SUCCESS(error)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:4867
never evaluated: error != U_BUFFER_OVERFLOW_ERROR
0-4867
604 qDebug() << "convertToUnicode failed:" << u_errorName(error);
never executed (the execution status of this line is deduced): QMessageLogger("codecs/qicucodec.cpp", 604, __PRETTY_FUNCTION__).debug() << "convertToUnicode failed:" << u_errorName_44(error);
-
605 break;
never executed: break;
0
606 } -
607 -
608 convertedChars = uc - (UChar *)string.data();
executed (the execution status of this line is deduced): convertedChars = uc - (UChar *)string.data();
-
609 if (chars >= end)
partially evaluated: chars >= end
TRUEFALSE
yes
Evaluation Count:4867
no
Evaluation Count:0
0-4867
610 break;
executed: break;
Execution Count:4867
4867
611 string.resize(string.length()*2);
never executed (the execution status of this line is deduced): string.resize(string.length()*2);
-
612 }
never executed: }
0
613 string.resize(convertedChars);
executed (the execution status of this line is deduced): string.resize(convertedChars);
-
614 -
615 if (!state)
evaluated: !state
TRUEFALSE
yes
Evaluation Count:3992
yes
Evaluation Count:875
875-3992
616 ucnv_close(conv);
executed: ucnv_close_44(conv);
Execution Count:3992
3992
617 return string;
executed: return string;
Execution Count:4867
4867
618} -
619 -
620 -
621QByteArray QIcuCodec::convertFromUnicode(const QChar *unicode, int length, QTextCodec::ConverterState *state) const -
622{ -
623 UConverter *conv = getConverter(state);
executed (the execution status of this line is deduced): UConverter *conv = getConverter(state);
-
624 -
625 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)));
-
626 QByteArray string(requiredLength, Qt::Uninitialized);
executed (the execution status of this line is deduced): QByteArray string(requiredLength, Qt::Uninitialized);
-
627 -
628 const UChar *uc = (const UChar *)unicode;
executed (the execution status of this line is deduced): const UChar *uc = (const UChar *)unicode;
-
629 const UChar *end = uc + length;
executed (the execution status of this line is deduced): const UChar *end = uc + length;
-
630 int convertedChars = 0;
executed (the execution status of this line is deduced): int convertedChars = 0;
-
631 while (1) {
partially evaluated: 1
TRUEFALSE
yes
Evaluation Count:90909
no
Evaluation Count:0
0-90909
632 char *ch = (char *)string.data();
executed (the execution status of this line is deduced): char *ch = (char *)string.data();
-
633 char *chEnd = ch + string.length();
executed (the execution status of this line is deduced): char *chEnd = ch + string.length();
-
634 ch += convertedChars;
executed (the execution status of this line is deduced): ch += convertedChars;
-
635 UErrorCode error = U_ZERO_ERROR;
executed (the execution status of this line is deduced): UErrorCode error = U_ZERO_ERROR;
-
636 ucnv_fromUnicode(conv,
executed (the execution status of this line is deduced): ucnv_fromUnicode_44(conv,
-
637 &ch, chEnd,
executed (the execution status of this line is deduced): &ch, chEnd,
-
638 &uc, end,
executed (the execution status of this line is deduced): &uc, end,
-
639 0, false, &error);
executed (the execution status of this line is deduced): 0, false, &error);
-
640 if (!U_SUCCESS(error))
partially evaluated: !U_SUCCESS(error)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:90911
0-90911
641 qDebug() << "convertFromUnicode failed:" << u_errorName(error);
never executed: QMessageLogger("codecs/qicucodec.cpp", 641, __PRETTY_FUNCTION__).debug() << "convertFromUnicode failed:" << u_errorName_44(error);
0
642 convertedChars = ch - string.data();
executed (the execution status of this line is deduced): convertedChars = ch - string.data();
-
643 if (uc >= end)
partially evaluated: uc >= end
TRUEFALSE
yes
Evaluation Count:90911
no
Evaluation Count:0
0-90911
644 break;
executed: break;
Execution Count:90911
90911
645 string.resize(string.length()*2);
never executed (the execution status of this line is deduced): string.resize(string.length()*2);
-
646 }
never executed: }
0
647 string.resize(convertedChars);
executed (the execution status of this line is deduced): string.resize(convertedChars);
-
648 -
649 if (!state)
evaluated: !state
TRUEFALSE
yes
Evaluation Count:2861
yes
Evaluation Count:88047
2861-88047
650 ucnv_close(conv);
executed: ucnv_close_44(conv);
Execution Count:2862
2862
651 -
652 return string;
executed: return string;
Execution Count:90911
90911
653} -
654 -
655 -
656QByteArray QIcuCodec::name() const -
657{ -
658 return m_name;
executed: return m_name;
Execution Count:7049
7049
659} -
660 -
661 -
662QList<QByteArray> QIcuCodec::aliases() const -
663{ -
664 UErrorCode error = U_ZERO_ERROR;
executed (the execution status of this line is deduced): UErrorCode error = U_ZERO_ERROR;
-
665 -
666 int n = ucnv_countAliases(m_name, &error);
executed (the execution status of this line is deduced): int n = ucnv_countAliases_44(m_name, &error);
-
667 -
668 QList<QByteArray> aliases;
executed (the execution status of this line is deduced): QList<QByteArray> aliases;
-
669 for (int i = 0; i < n; ++i) {
evaluated: i < n
TRUEFALSE
yes
Evaluation Count:51121
yes
Evaluation Count:7033
7033-51121
670 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);
-
671 // skip the canonical name -
672 if (!a || !qstrcmp(a, m_name))
partially evaluated: !a
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:51121
evaluated: !qstrcmp(a, m_name)
TRUEFALSE
yes
Evaluation Count:7033
yes
Evaluation Count:44088
0-51121
673 continue;
executed: continue;
Execution Count:7033
7033
674 aliases += a;
executed (the execution status of this line is deduced): aliases += a;
-
675 }
executed: }
Execution Count:44088
44088
676 -
677 return aliases;
executed: return aliases;
Execution Count:7033
7033
678} -
679 -
680 -
681int QIcuCodec::mibEnum() const -
682{ -
683 for (int i = 0; i < mibToNameSize; ++i) {
evaluated: i < mibToNameSize
TRUEFALSE
yes
Evaluation Count:437598
yes
Evaluation Count:336
336-437598
684 if (qTextCodecNameMatch(m_name, (mibToNameTable + mibToName[i].index)))
evaluated: qTextCodecNameMatch(m_name, (mibToNameTable + mibToName[i].index))
TRUEFALSE
yes
Evaluation Count:5918
yes
Evaluation Count:431680
5918-431680
685 return mibToName[i].mib;
executed: return mibToName[i].mib;
Execution Count:5918
5918
686 }
executed: }
Execution Count:431680
431680
687 -
688 return 0;
executed: return 0;
Execution Count:336
336
689} -
690 -
691QT_END_NAMESPACE -
692 -
693#endif // QT_NO_TEXTCODEC -
694 -
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial