| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/corelib/codecs/qlatincodec.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 "qlatincodec_p.h" | - | ||||||||||||
| 41 | #include "qlist.h" | - | ||||||||||||
| 42 | - | |||||||||||||
| 43 | #ifndef QT_NO_TEXTCODEC | - | ||||||||||||
| 44 | - | |||||||||||||
| 45 | QT_BEGIN_NAMESPACE | - | ||||||||||||
| 46 | - | |||||||||||||
| 47 | QLatin1Codec::~QLatin1Codec() | - | ||||||||||||
| 48 | { | - | ||||||||||||
| 49 | } | - | ||||||||||||
| 50 | - | |||||||||||||
| 51 | QString QLatin1Codec::convertToUnicode(const char *chars, int len, ConverterState *) const | - | ||||||||||||
| 52 | { | - | ||||||||||||
| 53 | if (chars == 0)
| 0-122 | ||||||||||||
| 54 | return QString(); never executed: return QString(); | 0 | ||||||||||||
| 55 | - | |||||||||||||
| 56 | return QString::fromLatin1(chars, len); executed 122 times by 5 tests: return QString::fromLatin1(chars, len);Executed by:
| 122 | ||||||||||||
| 57 | } | - | ||||||||||||
| 58 | - | |||||||||||||
| 59 | - | |||||||||||||
| 60 | QByteArray QLatin1Codec::convertFromUnicode(const QChar *ch, int len, ConverterState *state) const | - | ||||||||||||
| 61 | { | - | ||||||||||||
| 62 | const char replacement = (state && state->flags & ConvertInvalidToNull) ? 0 : '?';
| 38-63 | ||||||||||||
| 63 | QByteArray r(len, Qt::Uninitialized); | - | ||||||||||||
| 64 | char *d = r.data(); | - | ||||||||||||
| 65 | int invalid = 0; | - | ||||||||||||
| 66 | for (int i = 0; i < len; ++i) {
| 101-11686 | ||||||||||||
| 67 | if (ch[i] > 0xff) {
| 8-11678 | ||||||||||||
| 68 | d[i] = replacement; | - | ||||||||||||
| 69 | ++invalid; | - | ||||||||||||
| 70 | } else { executed 8 times by 1 test: end of blockExecuted by:
| 8 | ||||||||||||
| 71 | d[i] = (char)ch[i].cell(); | - | ||||||||||||
| 72 | } executed 11678 times by 4 tests: end of blockExecuted by:
| 11678 | ||||||||||||
| 73 | } | - | ||||||||||||
| 74 | if (state) {
| 38-63 | ||||||||||||
| 75 | state->invalidChars += invalid; | - | ||||||||||||
| 76 | } executed 38 times by 2 tests: end of blockExecuted by:
| 38 | ||||||||||||
| 77 | return r; executed 101 times by 4 tests: return r;Executed by:
| 101 | ||||||||||||
| 78 | } | - | ||||||||||||
| 79 | - | |||||||||||||
| 80 | QByteArray QLatin1Codec::name() const | - | ||||||||||||
| 81 | { | - | ||||||||||||
| 82 | return "ISO-8859-1"; executed 148 times by 7 tests: return "ISO-8859-1";Executed by:
| 148 | ||||||||||||
| 83 | } | - | ||||||||||||
| 84 | - | |||||||||||||
| 85 | QList<QByteArray> QLatin1Codec::aliases() const | - | ||||||||||||
| 86 | { | - | ||||||||||||
| 87 | QList<QByteArray> list; | - | ||||||||||||
| 88 | list << "latin1" | - | ||||||||||||
| 89 | << "CP819" | - | ||||||||||||
| 90 | << "IBM819" | - | ||||||||||||
| 91 | << "iso-ir-100" | - | ||||||||||||
| 92 | << "csISOLatin1"; | - | ||||||||||||
| 93 | return list; executed 142 times by 6 tests: return list;Executed by:
| 142 | ||||||||||||
| 94 | } | - | ||||||||||||
| 95 | - | |||||||||||||
| 96 | - | |||||||||||||
| 97 | int QLatin1Codec::mibEnum() const | - | ||||||||||||
| 98 | { | - | ||||||||||||
| 99 | return 4; executed 36 times by 2 tests: return 4;Executed by:
| 36 | ||||||||||||
| 100 | } | - | ||||||||||||
| 101 | - | |||||||||||||
| 102 | - | |||||||||||||
| 103 | QLatin15Codec::~QLatin15Codec() | - | ||||||||||||
| 104 | { | - | ||||||||||||
| 105 | } | - | ||||||||||||
| 106 | - | |||||||||||||
| 107 | QString QLatin15Codec::convertToUnicode(const char* chars, int len, ConverterState *) const | - | ||||||||||||
| 108 | { | - | ||||||||||||
| 109 | if (chars == 0)
| 0 | ||||||||||||
| 110 | return QString(); never executed: return QString(); | 0 | ||||||||||||
| 111 | - | |||||||||||||
| 112 | QString str = QString::fromLatin1(chars, len); | - | ||||||||||||
| 113 | QChar *uc = str.data(); | - | ||||||||||||
| 114 | while(len--) {
| 0 | ||||||||||||
| 115 | switch(uc->unicode()) { | - | ||||||||||||
| 116 | case 0xa4: never executed: case 0xa4: | 0 | ||||||||||||
| 117 | *uc = 0x20ac; | - | ||||||||||||
| 118 | break; never executed: break; | 0 | ||||||||||||
| 119 | case 0xa6: never executed: case 0xa6: | 0 | ||||||||||||
| 120 | *uc = 0x0160; | - | ||||||||||||
| 121 | break; never executed: break; | 0 | ||||||||||||
| 122 | case 0xa8: never executed: case 0xa8: | 0 | ||||||||||||
| 123 | *uc = 0x0161; | - | ||||||||||||
| 124 | break; never executed: break; | 0 | ||||||||||||
| 125 | case 0xb4: never executed: case 0xb4: | 0 | ||||||||||||
| 126 | *uc = 0x017d; | - | ||||||||||||
| 127 | break; never executed: break; | 0 | ||||||||||||
| 128 | case 0xb8: never executed: case 0xb8: | 0 | ||||||||||||
| 129 | *uc = 0x017e; | - | ||||||||||||
| 130 | break; never executed: break; | 0 | ||||||||||||
| 131 | case 0xbc: never executed: case 0xbc: | 0 | ||||||||||||
| 132 | *uc = 0x0152; | - | ||||||||||||
| 133 | break; never executed: break; | 0 | ||||||||||||
| 134 | case 0xbd: never executed: case 0xbd: | 0 | ||||||||||||
| 135 | *uc = 0x0153; | - | ||||||||||||
| 136 | break; never executed: break; | 0 | ||||||||||||
| 137 | case 0xbe: never executed: case 0xbe: | 0 | ||||||||||||
| 138 | *uc = 0x0178; | - | ||||||||||||
| 139 | break; never executed: break; | 0 | ||||||||||||
| 140 | default: never executed: default: | 0 | ||||||||||||
| 141 | break; never executed: break; | 0 | ||||||||||||
| 142 | } | - | ||||||||||||
| 143 | uc++; | - | ||||||||||||
| 144 | } never executed: end of block | 0 | ||||||||||||
| 145 | return str; never executed: return str; | 0 | ||||||||||||
| 146 | } | - | ||||||||||||
| 147 | - | |||||||||||||
| 148 | QByteArray QLatin15Codec::convertFromUnicode(const QChar *in, int length, ConverterState *state) const | - | ||||||||||||
| 149 | { | - | ||||||||||||
| 150 | const char replacement = (state && state->flags & ConvertInvalidToNull) ? 0 : '?';
| 0 | ||||||||||||
| 151 | QByteArray r(length, Qt::Uninitialized); | - | ||||||||||||
| 152 | char *d = r.data(); | - | ||||||||||||
| 153 | int invalid = 0; | - | ||||||||||||
| 154 | for (int i = 0; i < length; ++i) {
| 0 | ||||||||||||
| 155 | uchar c; | - | ||||||||||||
| 156 | ushort uc = in[i].unicode(); | - | ||||||||||||
| 157 | if (uc < 0x0100) {
| 0 | ||||||||||||
| 158 | if (uc > 0xa3) {
| 0 | ||||||||||||
| 159 | switch(uc) { | - | ||||||||||||
| 160 | case 0xa4: never executed: case 0xa4: | 0 | ||||||||||||
| 161 | case 0xa6: never executed: case 0xa6: | 0 | ||||||||||||
| 162 | case 0xa8: never executed: case 0xa8: | 0 | ||||||||||||
| 163 | case 0xb4: never executed: case 0xb4: | 0 | ||||||||||||
| 164 | case 0xb8: never executed: case 0xb8: | 0 | ||||||||||||
| 165 | case 0xbc: never executed: case 0xbc: | 0 | ||||||||||||
| 166 | case 0xbd: never executed: case 0xbd: | 0 | ||||||||||||
| 167 | case 0xbe: never executed: case 0xbe: | 0 | ||||||||||||
| 168 | c = replacement; | - | ||||||||||||
| 169 | ++invalid; | - | ||||||||||||
| 170 | break; never executed: break; | 0 | ||||||||||||
| 171 | default: never executed: default: | 0 | ||||||||||||
| 172 | c = (unsigned char) uc; | - | ||||||||||||
| 173 | break; never executed: break; | 0 | ||||||||||||
| 174 | } | - | ||||||||||||
| 175 | } else { | - | ||||||||||||
| 176 | c = (unsigned char) uc; | - | ||||||||||||
| 177 | } never executed: end of block | 0 | ||||||||||||
| 178 | } else { | - | ||||||||||||
| 179 | if (uc == 0x20ac)
| 0 | ||||||||||||
| 180 | c = 0xa4; never executed: c = 0xa4; | 0 | ||||||||||||
| 181 | else if ((uc & 0xff00) == 0x0100) {
| 0 | ||||||||||||
| 182 | switch(uc) { | - | ||||||||||||
| 183 | case 0x0160: never executed: case 0x0160: | 0 | ||||||||||||
| 184 | c = 0xa6; | - | ||||||||||||
| 185 | break; never executed: break; | 0 | ||||||||||||
| 186 | case 0x0161: never executed: case 0x0161: | 0 | ||||||||||||
| 187 | c = 0xa8; | - | ||||||||||||
| 188 | break; never executed: break; | 0 | ||||||||||||
| 189 | case 0x017d: never executed: case 0x017d: | 0 | ||||||||||||
| 190 | c = 0xb4; | - | ||||||||||||
| 191 | break; never executed: break; | 0 | ||||||||||||
| 192 | case 0x017e: never executed: case 0x017e: | 0 | ||||||||||||
| 193 | c = 0xb8; | - | ||||||||||||
| 194 | break; never executed: break; | 0 | ||||||||||||
| 195 | case 0x0152: never executed: case 0x0152: | 0 | ||||||||||||
| 196 | c = 0xbc; | - | ||||||||||||
| 197 | break; never executed: break; | 0 | ||||||||||||
| 198 | case 0x0153: never executed: case 0x0153: | 0 | ||||||||||||
| 199 | c = 0xbd; | - | ||||||||||||
| 200 | break; never executed: break; | 0 | ||||||||||||
| 201 | case 0x0178: never executed: case 0x0178: | 0 | ||||||||||||
| 202 | c = 0xbe; | - | ||||||||||||
| 203 | break; never executed: break; | 0 | ||||||||||||
| 204 | default: never executed: default: | 0 | ||||||||||||
| 205 | c = replacement; | - | ||||||||||||
| 206 | ++invalid; | - | ||||||||||||
| 207 | } never executed: end of block | 0 | ||||||||||||
| 208 | } else { | - | ||||||||||||
| 209 | c = replacement; | - | ||||||||||||
| 210 | ++invalid; | - | ||||||||||||
| 211 | } never executed: end of block | 0 | ||||||||||||
| 212 | } | - | ||||||||||||
| 213 | d[i] = (char)c; | - | ||||||||||||
| 214 | } never executed: end of block | 0 | ||||||||||||
| 215 | if (state) {
| 0 | ||||||||||||
| 216 | state->remainingChars = 0; | - | ||||||||||||
| 217 | state->invalidChars += invalid; | - | ||||||||||||
| 218 | } never executed: end of block | 0 | ||||||||||||
| 219 | return r; never executed: return r; | 0 | ||||||||||||
| 220 | } | - | ||||||||||||
| 221 | - | |||||||||||||
| 222 | - | |||||||||||||
| 223 | QByteArray QLatin15Codec::name() const | - | ||||||||||||
| 224 | { | - | ||||||||||||
| 225 | return "ISO-8859-15"; never executed: return "ISO-8859-15"; | 0 | ||||||||||||
| 226 | } | - | ||||||||||||
| 227 | - | |||||||||||||
| 228 | QList<QByteArray> QLatin15Codec::aliases() const | - | ||||||||||||
| 229 | { | - | ||||||||||||
| 230 | QList<QByteArray> list; | - | ||||||||||||
| 231 | list << "latin9"; | - | ||||||||||||
| 232 | return list; never executed: return list; | 0 | ||||||||||||
| 233 | } | - | ||||||||||||
| 234 | - | |||||||||||||
| 235 | int QLatin15Codec::mibEnum() const | - | ||||||||||||
| 236 | { | - | ||||||||||||
| 237 | return 111; never executed: return 111; | 0 | ||||||||||||
| 238 | } | - | ||||||||||||
| 239 | - | |||||||||||||
| 240 | QT_END_NAMESPACE | - | ||||||||||||
| 241 | - | |||||||||||||
| 242 | #endif // QT_NO_TEXTCODEC | - | ||||||||||||
| Source code | Switch to Preprocessed file |