| Line | Source Code | Coverage |
|---|
| 1 | | - | | 2 | | - | | 3 | | - | | 4 | | - | | 5 | | - | | 6 | | - | | 7 | | - | | 8 | static void qIcuCodecStateFree(QTextCodec::ConverterState *state) | - | | 9 | { | - | | 10 | ucnv_close_44(static_cast<UConverter *>(state->d)); | - | | 11 | } | - | | 12 | | - | | 13 | bool qTextCodecNameMatch(const char *n, const char *h) | - | | 14 | { | - | | 15 | return ucnv_compareNames_44(n, h) == 0; | - | | 16 | } | - | | 17 | struct MibToName { | - | | 18 | short mib; | - | | 19 | short index; | - | | 20 | }; | - | | 21 | | - | | 22 | static MibToName mibToName[] = { | - | | 23 | { 3, 0 }, | - | | 24 | { 4, 9 }, | - | | 25 | { 5, 20 }, | - | | 26 | { 6, 31 }, | - | | 27 | { 7, 42 }, | - | | 28 | { 8, 53 }, | - | | 29 | { 9, 64 }, | - | | 30 | { 10, 75 }, | - | | 31 | { 11, 86 }, | - | | 32 | { 12, 97 }, | - | | 33 | { 13, 108 }, | - | | 34 | { 16, 120 }, | - | | 35 | { 17, 134 }, | - | | 36 | { 18, 144 }, | - | | 37 | { 30, 151 }, | - | | 38 | { 36, 160 }, | - | | 39 | { 37, 167 }, | - | | 40 | { 38, 179 }, | - | | 41 | { 39, 186 }, | - | | 42 | { 40, 198 }, | - | | 43 | { 57, 212 }, | - | | 44 | { 81, 223 }, | - | | 45 | { 82, 234 }, | - | | 46 | { 84, 245 }, | - | | 47 | { 85, 256 }, | - | | 48 | { 104, 267 }, | - | | 49 | { 105, 279 }, | - | | 50 | { 106, 295 }, | - | | 51 | { 109, 301 }, | - | | 52 | { 110, 313 }, | - | | 53 | { 111, 325 }, | - | | 54 | { 113, 337 }, | - | | 55 | { 114, 341 }, | - | | 56 | { 1000, 349 }, | - | | 57 | { 1001, 356 }, | - | | 58 | { 1011, 363 }, | - | | 59 | { 1012, 368 }, | - | | 60 | { 1013, 374 }, | - | | 61 | { 1014, 383 }, | - | | 62 | { 1015, 392 }, | - | | 63 | { 1016, 399 }, | - | | 64 | { 1017, 406 }, | - | | 65 | { 1018, 413 }, | - | | 66 | { 1019, 422 }, | - | | 67 | { 1020, 431 }, | - | | 68 | { 2004, 438 }, | - | | 69 | { 2005, 448 }, | - | | 70 | { 2009, 472 }, | - | | 71 | { 2013, 479 }, | - | | 72 | { 2016, 486 }, | - | | 73 | { 2024, 495 }, | - | | 74 | { 2025, 505 }, | - | | 75 | { 2026, 512 }, | - | | 76 | { 2027, 517 }, | - | | 77 | { 2028, 527 }, | - | | 78 | { 2030, 534 }, | - | | 79 | { 2033, 541 }, | - | | 80 | { 2034, 548 }, | - | | 81 | { 2035, 555 }, | - | | 82 | { 2037, 562 }, | - | | 83 | { 2038, 569 }, | - | | 84 | { 2039, 576 }, | - | | 85 | { 2040, 583 }, | - | | 86 | { 2041, 590 }, | - | | 87 | { 2043, 597 }, | - | | 88 | { 2011, 604 }, | - | | 89 | { 2044, 611 }, | - | | 90 | { 2045, 618 }, | - | | 91 | { 2010, 624 }, | - | | 92 | { 2046, 631 }, | - | | 93 | { 2047, 638 }, | - | | 94 | { 2048, 645 }, | - | | 95 | { 2049, 652 }, | - | | 96 | { 2050, 659 }, | - | | 97 | { 2051, 666 }, | - | | 98 | { 2052, 673 }, | - | | 99 | { 2053, 680 }, | - | | 100 | { 2054, 687 }, | - | | 101 | { 2055, 694 }, | - | | 102 | { 2056, 701 }, | - | | 103 | { 2062, 708 }, | - | | 104 | { 2063, 715 }, | - | | 105 | { 2084, 723 }, | - | | 106 | { 2085, 730 }, | - | | 107 | { 2086, 741 }, | - | | 108 | { 2087, 748 }, | - | | 109 | { 2088, 755 }, | - | | 110 | { 2089, 762 }, | - | | 111 | { 2091, 771 }, | - | | 112 | { 2092, 780 }, | - | | 113 | { 2093, 789 }, | - | | 114 | { 2094, 798 }, | - | | 115 | { 2095, 807 }, | - | | 116 | { 2096, 816 }, | - | | 117 | { 2097, 825 }, | - | | 118 | { 2098, 834 }, | - | | 119 | { 2099, 843 }, | - | | 120 | { 2100, 852 }, | - | | 121 | { 2101, 861 }, | - | | 122 | { 2102, 872 }, | - | | 123 | { 2250, 880 }, | - | | 124 | { 2251, 893 }, | - | | 125 | { 2252, 906 }, | - | | 126 | { 2253, 919 }, | - | | 127 | { 2254, 932 }, | - | | 128 | { 2255, 945 }, | - | | 129 | { 2256, 958 }, | - | | 130 | { 2257, 971 }, | - | | 131 | { 2258, 984 }, | - | | 132 | { 2259, 997 }, | - | | 133 | }; | - | | 134 | int mibToNameSize = sizeof(mibToName)/sizeof(MibToName); | - | | 135 | | - | | 136 | static const char mibToNameTable[] = | - | | 137 | "US-ASCII\0" | - | | 138 | "ISO-8859-1\0" | - | | 139 | "ISO-8859-2\0" | - | | 140 | "ISO-8859-3\0" | - | | 141 | "ISO-8859-4\0" | - | | 142 | "ISO-8859-5\0" | - | | 143 | "ISO-8859-6\0" | - | | 144 | "ISO-8859-7\0" | - | | 145 | "ISO-8859-8\0" | - | | 146 | "ISO-8859-9\0" | - | | 147 | "ISO-8859-10\0" | - | | 148 | "ISO-2022-JP-1\0" | - | | 149 | "Shift_JIS\0" | - | | 150 | "EUC-JP\0" | - | | 151 | "US-ASCII\0" | - | | 152 | "EUC-KR\0" | - | | 153 | "ISO-2022-KR\0" | - | | 154 | "EUC-KR\0" | - | | 155 | "ISO-2022-JP\0" | - | | 156 | "ISO-2022-JP-2\0" | - | | 157 | "GB_2312-80\0" | - | | 158 | "ISO-8859-6\0" | - | | 159 | "ISO-8859-6\0" | - | | 160 | "ISO-8859-8\0" | - | | 161 | "ISO-8859-8\0" | - | | 162 | "ISO-2022-CN\0" | - | | 163 | "ISO-2022-CN-EXT\0" | - | | 164 | "UTF-8\0" | - | | 165 | "ISO-8859-13\0" | - | | 166 | "ISO-8859-14\0" | - | | 167 | "ISO-8859-15\0" | - | | 168 | "GBK\0" | - | | 169 | "GB18030\0" | - | | 170 | "UTF-16\0" | - | | 171 | "UTF-32\0" | - | | 172 | "SCSU\0" | - | | 173 | "UTF-7\0" | - | | 174 | "UTF-16BE\0" | - | | 175 | "UTF-16LE\0" | - | | 176 | "UTF-16\0" | - | | 177 | "CESU-8\0" | - | | 178 | "UTF-32\0" | - | | 179 | "UTF-32BE\0" | - | | 180 | "UTF-32LE\0" | - | | 181 | "BOCU-1\0" | - | | 182 | "hp-roman8\0" | - | | 183 | "Adobe-Standard-Encoding\0" | - | | 184 | "IBM850\0" | - | | 185 | "IBM862\0" | - | | 186 | "IBM-Thai\0" | - | | 187 | "Shift_JIS\0" | - | | 188 | "GB2312\0" | - | | 189 | "Big5\0" | - | | 190 | "macintosh\0" | - | | 191 | "IBM037\0" | - | | 192 | "IBM273\0" | - | | 193 | "IBM277\0" | - | | 194 | "IBM278\0" | - | | 195 | "IBM280\0" | - | | 196 | "IBM284\0" | - | | 197 | "IBM285\0" | - | | 198 | "IBM290\0" | - | | 199 | "IBM297\0" | - | | 200 | "IBM420\0" | - | | 201 | "IBM424\0" | - | | 202 | "IBM437\0" | - | | 203 | "IBM500\0" | - | | 204 | "cp851\0" | - | | 205 | "IBM852\0" | - | | 206 | "IBM855\0" | - | | 207 | "IBM857\0" | - | | 208 | "IBM860\0" | - | | 209 | "IBM861\0" | - | | 210 | "IBM863\0" | - | | 211 | "IBM864\0" | - | | 212 | "IBM865\0" | - | | 213 | "IBM868\0" | - | | 214 | "IBM869\0" | - | | 215 | "IBM870\0" | - | | 216 | "IBM871\0" | - | | 217 | "IBM918\0" | - | | 218 | "IBM1026\0" | - | | 219 | "KOI8-R\0" | - | | 220 | "HZ-GB-2312\0" | - | | 221 | "IBM866\0" | - | | 222 | "IBM775\0" | - | | 223 | "KOI8-U\0" | - | | 224 | "IBM00858\0" | - | | 225 | "IBM01140\0" | - | | 226 | "IBM01141\0" | - | | 227 | "IBM01142\0" | - | | 228 | "IBM01143\0" | - | | 229 | "IBM01144\0" | - | | 230 | "IBM01145\0" | - | | 231 | "IBM01146\0" | - | | 232 | "IBM01147\0" | - | | 233 | "IBM01148\0" | - | | 234 | "IBM01149\0" | - | | 235 | "Big5-HKSCS\0" | - | | 236 | "IBM1047\0" | - | | 237 | "windows-1250\0" | - | | 238 | "windows-1251\0" | - | | 239 | "windows-1252\0" | - | | 240 | "windows-1253\0" | - | | 241 | "windows-1254\0" | - | | 242 | "windows-1255\0" | - | | 243 | "windows-1256\0" | - | | 244 | "windows-1257\0" | - | | 245 | "windows-1258\0" | - | | 246 | "TIS-620\0"; | - | | 247 | | - | | 248 | static QTextCodec *loadQtCodec(const char *name) | - | | 249 | { | - | | 250 | if (!strcmp(name, "UTF-8")) | - | | 251 | return new QUtf8Codec; | - | | 252 | if (!strcmp(name, "UTF-16")) | - | | 253 | return new QUtf16Codec; | - | | 254 | if (!strcmp(name, "ISO-8859-1")) | - | | 255 | return new QLatin1Codec; | - | | 256 | if (!strcmp(name, "UTF-16BE")) | - | | 257 | return new QUtf16BECodec; | - | | 258 | if (!strcmp(name, "UTF-16LE")) | - | | 259 | return new QUtf16LECodec; | - | | 260 | if (!strcmp(name, "UTF-32")) | - | | 261 | return new QUtf32Codec; | - | | 262 | if (!strcmp(name, "UTF-32BE")) | - | | 263 | return new QUtf32BECodec; | - | | 264 | if (!strcmp(name, "UTF-32LE")) | - | | 265 | return new QUtf32LECodec; | - | | 266 | | - | | 267 | if (!strcmp(name, "TSCII")) | - | | 268 | return new QTsciiCodec; | - | | 269 | if (!qstrnicmp(name, "iscii", 5)) | - | | 270 | return QIsciiCodec::create(name); | - | | 271 | | - | | 272 | | - | | 273 | return 0; | - | | 274 | } | - | | 275 | | - | | 276 | | - | | 277 | QList<QByteArray> QIcuCodec::availableCodecs() | - | | 278 | { | - | | 279 | QList<QByteArray> codecs; | - | | 280 | int n = ucnv_countAvailable_44(); | - | | 281 | for (int i = 0; i < n; ++i) { | - | | 282 | const char *name = ucnv_getAvailableName_44(i); | - | | 283 | | - | | 284 | UErrorCode error = U_ZERO_ERROR; | - | | 285 | const char *standardName = ucnv_getStandardName_44(name, "MIME", &error); | - | | 286 | if (U_FAILURE(error) || !standardName) { | - | | 287 | error = U_ZERO_ERROR; | - | | 288 | standardName = ucnv_getStandardName_44(name, "IANA", &error); | - | | 289 | } | - | | 290 | if (U_FAILURE(error)) | - | | 291 | continue; | - | | 292 | | - | | 293 | error = U_ZERO_ERROR; | - | | 294 | int ac = ucnv_countAliases_44(standardName, &error); | - | | 295 | if (U_FAILURE(error)) | - | | 296 | continue; | - | | 297 | for (int j = 0; j < ac; ++j) { | - | | 298 | error = U_ZERO_ERROR; | - | | 299 | const char *alias = ucnv_getAlias_44(standardName, j, &error); | - | | 300 | if (!U_SUCCESS(error)) | - | | 301 | continue; | - | | 302 | codecs += alias; | - | | 303 | } | - | | 304 | } | - | | 305 | | - | | 306 | | - | | 307 | codecs += "TSCII"; | - | | 308 | | - | | 309 | return codecs; | - | | 310 | } | - | | 311 | | - | | 312 | | - | | 313 | QList<int> QIcuCodec::availableMibs() | - | | 314 | { | - | | 315 | QList<int> mibs; | - | | 316 | for (int i = 0; i < mibToNameSize; ++i) | - | | 317 | mibs += mibToName[i].mib; | - | | 318 | | - | | 319 | | - | | 320 | mibs += 2107; | - | | 321 | | - | | 322 | return mibs; | - | | 323 | } | - | | 324 | | - | | 325 | QTextCodec *QIcuCodec::defaultCodecUnlocked() | - | | 326 | { | - | | 327 | QCoreGlobalData *globalData = QCoreGlobalData::instance(); | - | | 328 | if (!globalData) | - | | 329 | return 0; | - | | 330 | QTextCodec *c = globalData->codecForLocale.loadAcquire(); | - | | 331 | if (c) | - | | 332 | return c; | - | | 333 | | - | | 334 | | - | | 335 | | - | | 336 | | - | | 337 | const char *name = ucnv_getDefaultName_44(); | - | | 338 | | - | | 339 | c = codecForNameUnlocked(name); | - | | 340 | globalData->codecForLocale.storeRelease(c); | - | | 341 | return c; | - | | 342 | } | - | | 343 | | - | | 344 | | - | | 345 | QTextCodec *QIcuCodec::codecForNameUnlocked(const char *name) | - | | 346 | { | - | | 347 | | - | | 348 | if (!qstrcmp(name, "CP949")) evaluated: !qstrcmp(name, "CP949")| yes Evaluation Count:1 | yes Evaluation Count:11296 |
| 1-11296 | | 349 | name = "windows-949"; executed: name = "windows-949";Execution Count:1 | 1 | | 350 | | - | | 351 | if (!qstrcmp(name, "windows-874-2000") evaluated: !qstrcmp(name, "windows-874-2000")| yes Evaluation Count:7 | yes Evaluation Count:11290 |
| 7-11290 | | 352 | || !qstrcmp(name, "windows-874") evaluated: !qstrcmp(name, "windows-874")| yes Evaluation Count:7 | yes Evaluation Count:11283 |
| 7-11283 | | 353 | || !qstrcmp(name, "MS874") evaluated: !qstrcmp(name, "MS874")| yes Evaluation Count:7 | yes Evaluation Count:11276 |
| 7-11276 | | 354 | || !qstrcmp(name, "x-windows-874")) partially evaluated: !qstrcmp(name, "x-windows-874")| no Evaluation Count:0 | yes Evaluation Count:11276 |
| 0-11276 | | 355 | name = "TIS-620"; executed: name = "TIS-620";Execution Count:21 | 21 | | 356 | | - | | 357 | UErrorCode error = U_ZERO_ERROR; | - | | 358 | | - | | 359 | const char *standardName = ucnv_getStandardName_44(name, "MIME", &error); | - | | 360 | if (U_FAILURE(error) || !standardName) { evaluated: U_FAILURE(error)| yes Evaluation Count:1 | yes Evaluation Count:11296 |
evaluated: !standardName| yes Evaluation Count:3469 | yes Evaluation Count:7827 |
| 1-11296 | | 361 | error = U_ZERO_ERROR; | - | | 362 | standardName = ucnv_getStandardName_44(name, "IANA", &error); | - | | 363 | } executed: }Execution Count:3470 | 3470 | | 364 | bool qt_only = false; | - | | 365 | if (U_FAILURE(error) || !standardName) { evaluated: U_FAILURE(error)| yes Evaluation Count:1 | yes Evaluation Count:11296 |
evaluated: !standardName| yes Evaluation Count:74 | yes Evaluation Count:11222 |
| 1-11296 | | 366 | standardName = name; | - | | 367 | qt_only = true; | - | | 368 | } else { executed: }Execution Count:75 | 75 | | 369 | | - | | 370 | | - | | 371 | | - | | 372 | | - | | 373 | if (qstrcmp(standardName, "GB2312") == 0 || qstrcmp(standardName, "GB_2312-80") == 0) evaluated: qstrcmp(standardName, "GB2312") == 0| yes Evaluation Count:32 | yes Evaluation Count:11190 |
evaluated: qstrcmp(standardName, "GB_2312-80") == 0| yes Evaluation Count:25 | yes Evaluation Count:11165 |
| 25-11190 | | 374 | standardName = "GBK"; executed: standardName = "GBK";Execution Count:57 | 57 | | 375 | 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:11165 |
evaluated: qstrcmp(standardName, "EUC-KR") == 0| yes Evaluation Count:99 | yes Evaluation Count:11066 |
evaluated: qstrcmp(standardName, "cp1363") == 0| yes Evaluation Count:157 | yes Evaluation Count:10909 |
| 0-11165 | | 376 | standardName = "windows-949"; executed: standardName = "windows-949";Execution Count:256 | 256 | | 377 | } | - | | 378 | | - | | 379 | QCoreGlobalData *globalData = QCoreGlobalData::instance(); | - | | 380 | QTextCodecCache *cache = &globalData->codecCache; | - | | 381 | | - | | 382 | QTextCodec *codec; | - | | 383 | if (cache) { partially evaluated: cache| yes Evaluation Count:11297 | no Evaluation Count:0 |
| 0-11297 | | 384 | codec = cache->value(standardName); | - | | 385 | if (codec) evaluated: codec| yes Evaluation Count:10998 | yes Evaluation Count:299 |
| 299-10998 | | 386 | return codec; executed: return codec;Execution Count:10998 | 10998 | | 387 | } executed: }Execution Count:299 | 299 | | 388 | | - | | 389 | for (int i = 0; i < globalData->allCodecs.size(); ++i) { evaluated: i < globalData->allCodecs.size()| yes Evaluation Count:7533 | yes Evaluation Count:266 |
| 266-7533 | | 390 | QTextCodec *cursor = globalData->allCodecs.at(i); | - | | 391 | if (qTextCodecNameMatch(cursor->name(), standardName)) { evaluated: qTextCodecNameMatch(cursor->name(), standardName)| yes Evaluation Count:31 | yes Evaluation Count:7502 |
| 31-7502 | | 392 | if (cache) partially evaluated: cache| yes Evaluation Count:31 | no Evaluation Count:0 |
| 0-31 | | 393 | cache->insert(standardName, cursor); executed: cache->insert(standardName, cursor);Execution Count:31 | 31 | | 394 | return cursor; executed: return cursor;Execution Count:31 | 31 | | 395 | } | - | | 396 | QList<QByteArray> aliases = cursor->aliases(); | - | | 397 | for (int y = 0; y < aliases.size(); ++y) evaluated: y < aliases.size()| yes Evaluation Count:39694 | yes Evaluation Count:7500 |
| 7500-39694 | | 398 | if (qTextCodecNameMatch(aliases.at(y), standardName)) { evaluated: qTextCodecNameMatch(aliases.at(y), standardName)| yes Evaluation Count:2 | yes Evaluation Count:39692 |
| 2-39692 | | 399 | if (cache) partially evaluated: cache| yes Evaluation Count:2 | no Evaluation Count:0 |
| 0-2 | | 400 | cache->insert(standardName, cursor); executed: cache->insert(standardName, cursor);Execution Count:2 | 2 | | 401 | return cursor; executed: return cursor;Execution Count:2 | 2 | | 402 | } | - | | 403 | } executed: }Execution Count:7500 | 7500 | | 404 | | - | | 405 | QTextCodec *c = loadQtCodec(standardName); | - | | 406 | if (c) evaluated: c| yes Evaluation Count:155 | yes Evaluation Count:111 |
| 111-155 | | 407 | return c; executed: return c;Execution Count:155 | 155 | | 408 | | - | | 409 | if (qt_only) evaluated: qt_only| yes Evaluation Count:10 | yes Evaluation Count:101 |
| 10-101 | | 410 | return 0; executed: return 0;Execution Count:10 | 10 | | 411 | | - | | 412 | | - | | 413 | UConverter *conv = ucnv_open_44(standardName, &error); | - | | 414 | if (!conv) { partially evaluated: !conv| no Evaluation Count:0 | yes Evaluation Count:101 |
| 0-101 | | 415 | QMessageLogger("codecs/qicucodec.cpp", 518521, __PRETTY_FUNCTION__).debug() << "codecForName: ucnv_open failed" << standardName << u_errorName_44(error); | - | | 416 | return 0; never executed: return 0; | 0 | | 417 | } | - | | 418 | | - | | 419 | ucnv_close_44(conv); | - | | 420 | | - | | 421 | | - | | 422 | c = new QIcuCodec(standardName); | - | | 423 | if (cache) partially evaluated: cache| yes Evaluation Count:101 | no Evaluation Count:0 |
| 0-101 | | 424 | cache->insert(standardName, c); executed: cache->insert(standardName, c);Execution Count:101 | 101 | | 425 | return c; executed: return c;Execution Count:101 | 101 | | 426 | } | - | | 427 | | - | | 428 | | - | | 429 | QTextCodec *QIcuCodec::codecForMibUnlocked(int mib) | - | | 430 | { | - | | 431 | for (int i = 0; i < mibToNameSize; ++i) { | - | | 432 | if (mibToName[i].mib == mib) | - | | 433 | return codecForNameUnlocked(mibToNameTable + mibToName[i].index); | - | | 434 | } | - | | 435 | | - | | 436 | if (mib == 2107) | - | | 437 | return codecForNameUnlocked("TSCII"); | - | | 438 | | - | | 439 | return 0; | - | | 440 | } | - | | 441 | | - | | 442 | | - | | 443 | QIcuCodec::QIcuCodec(const char *name) | - | | 444 | : m_name(name) | - | | 445 | { | - | | 446 | } | - | | 447 | | - | | 448 | QIcuCodec::~QIcuCodec() | - | | 449 | { | - | | 450 | } | - | | 451 | | - | | 452 | UConverter *QIcuCodec::getConverter(QTextCodec::ConverterState *state) const | - | | 453 | { | - | | 454 | UConverter *conv = 0; | - | | 455 | if (state) { | - | | 456 | if (!state->d) { | - | | 457 | | - | | 458 | state->flags |= QTextCodec::FreeFunction; | - | | 459 | QTextCodecUnalignedPointer::encode(state->state_data, qIcuCodecStateFree); | - | | 460 | UErrorCode error = U_ZERO_ERROR; | - | | 461 | state->d = ucnv_open_44(m_name, &error); | - | | 462 | ucnv_setSubstChars_44(static_cast<UConverter *>(state->d), | - | | 463 | state->flags & QTextCodec::ConvertInvalidToNull ? "\0" : "?", 1, &error); | - | | 464 | if (U_FAILURE(error)) | - | | 465 | QMessageLogger("codecs/qicucodec.cpp", 568571, __PRETTY_FUNCTION__).debug() << "getConverter(state) ucnv_open failed" << m_name << u_errorName_44(error); | - | | 466 | } | - | | 467 | conv = static_cast<UConverter *>(state->d); | - | | 468 | } | - | | 469 | if (!conv) { | - | | 470 | | - | | 471 | UErrorCode error = U_ZERO_ERROR; | - | | 472 | conv = ucnv_open_44(m_name, &error); | - | | 473 | ucnv_setSubstChars_44(conv, "?", 1, &error); | - | | 474 | if (U_FAILURE(error)) | - | | 475 | QMessageLogger("codecs/qicucodec.cpp", 578581, __PRETTY_FUNCTION__).debug() << "getConverter(no state) ucnv_open failed" << m_name << u_errorName_44(error); | - | | 476 | } | - | | 477 | return conv; | - | | 478 | } | - | | 479 | | - | | 480 | QString QIcuCodec::convertToUnicode(const char *chars, int length, QTextCodec::ConverterState *state) const | - | | 481 | { | - | | 482 | UConverter *conv = getConverter(state); | - | | 483 | | - | | 484 | QString string(length + 2, Qt::Uninitialized); | - | | 485 | | - | | 486 | const char *end = chars + length; | - | | 487 | int convertedChars = 0; | - | | 488 | while (1) { | - | | 489 | UChar *uc = (UChar *)string.data(); | - | | 490 | UChar *ucEnd = uc + string.length(); | - | | 491 | uc += convertedChars; | - | | 492 | UErrorCode error = U_ZERO_ERROR; | - | | 493 | ucnv_toUnicode_44(conv, | - | | 494 | &uc, ucEnd, | - | | 495 | &chars, end, | - | | 496 | 0, false, &error); | - | | 497 | if (!U_SUCCESS(error) && error != U_BUFFER_OVERFLOW_ERROR) { | - | | 498 | QMessageLogger("codecs/qicucodec.cpp", 601604, __PRETTY_FUNCTION__).debug() << "convertToUnicode failed:" << u_errorName_44(error); | - | | 499 | break; | - | | 500 | } | - | | 501 | | - | | 502 | convertedChars = uc - (UChar *)string.data(); | - | | 503 | if (chars >= end) | - | | 504 | break; | - | | 505 | string.resize(string.length()*2); | - | | 506 | } | - | | 507 | string.resize(convertedChars); | - | | 508 | | - | | 509 | if (!state) | - | | 510 | ucnv_close_44(conv); | - | | 511 | return string; | - | | 512 | } | - | | 513 | | - | | 514 | | - | | 515 | QByteArray QIcuCodec::convertFromUnicode(const QChar *unicode, int length, QTextCodec::ConverterState *state) const | - | | 516 | { | - | | 517 | UConverter *conv = getConverter(state); | - | | 518 | | - | | 519 | int requiredLength = (((int32_t)(length)+10)*(int32_t)(ucnv_getMaxCharSize_44(conv))); | - | | 520 | QByteArray string(requiredLength, Qt::Uninitialized); | - | | 521 | | - | | 522 | const UChar *uc = (const UChar *)unicode; | - | | 523 | const UChar *end = uc + length; | - | | 524 | int convertedChars = 0; | - | | 525 | while (1) { | - | | 526 | char *ch = (char *)string.data(); | - | | 527 | char *chEnd = ch + string.length(); | - | | 528 | ch += convertedChars; | - | | 529 | UErrorCode error = U_ZERO_ERROR; | - | | 530 | ucnv_fromUnicode_44(conv, | - | | 531 | &ch, chEnd, | - | | 532 | &uc, end, | - | | 533 | 0, false, &error); | - | | 534 | if (!U_SUCCESS(error)) | - | | 535 | QMessageLogger("codecs/qicucodec.cpp", 638641, __PRETTY_FUNCTION__).debug() << "convertFromUnicode failed:" << u_errorName_44(error); | - | | 536 | convertedChars = ch - string.data(); | - | | 537 | if (uc >= end) | - | | 538 | break; | - | | 539 | string.resize(string.length()*2); | - | | 540 | } | - | | 541 | string.resize(convertedChars); | - | | 542 | | - | | 543 | if (!state) | - | | 544 | ucnv_close_44(conv); | - | | 545 | | - | | 546 | return string; | - | | 547 | } | - | | 548 | | - | | 549 | | - | | 550 | QByteArray QIcuCodec::name() const | - | | 551 | { | - | | 552 | return m_name; | - | | 553 | } | - | | 554 | | - | | 555 | | - | | 556 | QList<QByteArray> QIcuCodec::aliases() const | - | | 557 | { | - | | 558 | UErrorCode error = U_ZERO_ERROR; | - | | 559 | | - | | 560 | int n = ucnv_countAliases_44(m_name, &error); | - | | 561 | | - | | 562 | QList<QByteArray> aliases; | - | | 563 | for (int i = 0; i < n; ++i) { | - | | 564 | const char *a = ucnv_getAlias_44(m_name, i, &error); | - | | 565 | | - | | 566 | if (!a || !qstrcmp(a, m_name)) | - | | 567 | continue; | - | | 568 | aliases += a; | - | | 569 | } | - | | 570 | | - | | 571 | return aliases; | - | | 572 | } | - | | 573 | | - | | 574 | | - | | 575 | int QIcuCodec::mibEnum() const | - | | 576 | { | - | | 577 | for (int i = 0; i < mibToNameSize; ++i) { | - | | 578 | if (qTextCodecNameMatch(m_name, (mibToNameTable + mibToName[i].index))) | - | | 579 | return mibToName[i].mib; | - | | 580 | } | - | | 581 | | - | | 582 | return 0; | - | | 583 | } | - | | 584 | | - | | 585 | | - | | 586 | | - | | | |
|