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