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) 2015 The Qt Company Ltd. | - | ||||||||||||
4 | ** Contact: http://www.qt.io/licensing/ | - | ||||||||||||
5 | ** | - | ||||||||||||
6 | ** This file is part of the QtCore module of the Qt Toolkit. | - | ||||||||||||
7 | ** | - | ||||||||||||
8 | ** $QT_BEGIN_LICENSE:LGPL21$ | - | ||||||||||||
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 http://www.qt.io/terms-conditions. For further | - | ||||||||||||
15 | ** information use the contact form at http://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 2.1 or version 3 as published by the Free | - | ||||||||||||
20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and | - | ||||||||||||
21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the | - | ||||||||||||
22 | ** following information to ensure the GNU Lesser General Public License | - | ||||||||||||
23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and | - | ||||||||||||
24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - | ||||||||||||
25 | ** | - | ||||||||||||
26 | ** As a special exception, The Qt Company gives you certain additional | - | ||||||||||||
27 | ** rights. These rights are described in The Qt Company LGPL Exception | - | ||||||||||||
28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - | ||||||||||||
29 | ** | - | ||||||||||||
30 | ** $QT_END_LICENSE$ | - | ||||||||||||
31 | ** | - | ||||||||||||
32 | ****************************************************************************/ | - | ||||||||||||
33 | - | |||||||||||||
34 | #include "qlatincodec_p.h" | - | ||||||||||||
35 | #include "qlist.h" | - | ||||||||||||
36 | - | |||||||||||||
37 | #ifndef QT_NO_TEXTCODEC | - | ||||||||||||
38 | - | |||||||||||||
39 | QT_BEGIN_NAMESPACE | - | ||||||||||||
40 | - | |||||||||||||
41 | QLatin1Codec::~QLatin1Codec() | - | ||||||||||||
42 | { | - | ||||||||||||
43 | } | - | ||||||||||||
44 | - | |||||||||||||
45 | QString QLatin1Codec::convertToUnicode(const char *chars, int len, ConverterState *) const | - | ||||||||||||
46 | { | - | ||||||||||||
47 | if (chars == 0)
| 0-122 | ||||||||||||
48 | return QString(); never executed: return QString(); | 0 | ||||||||||||
49 | - | |||||||||||||
50 | return QString::fromLatin1(chars, len); executed 122 times by 5 tests: return QString::fromLatin1(chars, len); Executed by:
| 122 | ||||||||||||
51 | } | - | ||||||||||||
52 | - | |||||||||||||
53 | - | |||||||||||||
54 | QByteArray QLatin1Codec::convertFromUnicode(const QChar *ch, int len, ConverterState *state) const | - | ||||||||||||
55 | { | - | ||||||||||||
56 | const char replacement = (state && state->flags & ConvertInvalidToNull) ? 0 : '?';
| 38-63 | ||||||||||||
57 | QByteArray r(len, Qt::Uninitialized); | - | ||||||||||||
58 | char *d = r.data(); | - | ||||||||||||
59 | int invalid = 0; | - | ||||||||||||
60 | for (int i = 0; i < len; ++i) {
| 101-11686 | ||||||||||||
61 | if (ch[i] > 0xff) {
| 8-11678 | ||||||||||||
62 | d[i] = replacement; | - | ||||||||||||
63 | ++invalid; | - | ||||||||||||
64 | } else { executed 8 times by 1 test: end of block Executed by:
| 8 | ||||||||||||
65 | d[i] = (char)ch[i].cell(); | - | ||||||||||||
66 | } executed 11678 times by 4 tests: end of block Executed by:
| 11678 | ||||||||||||
67 | } | - | ||||||||||||
68 | if (state) {
| 38-63 | ||||||||||||
69 | state->invalidChars += invalid; | - | ||||||||||||
70 | } executed 38 times by 2 tests: end of block Executed by:
| 38 | ||||||||||||
71 | return r; executed 101 times by 4 tests: return r; Executed by:
| 101 | ||||||||||||
72 | } | - | ||||||||||||
73 | - | |||||||||||||
74 | QByteArray QLatin1Codec::name() const | - | ||||||||||||
75 | { | - | ||||||||||||
76 | return "ISO-8859-1"; executed 148 times by 7 tests: return "ISO-8859-1"; Executed by:
| 148 | ||||||||||||
77 | } | - | ||||||||||||
78 | - | |||||||||||||
79 | QList<QByteArray> QLatin1Codec::aliases() const | - | ||||||||||||
80 | { | - | ||||||||||||
81 | QList<QByteArray> list; | - | ||||||||||||
82 | list << "latin1" | - | ||||||||||||
83 | << "CP819" | - | ||||||||||||
84 | << "IBM819" | - | ||||||||||||
85 | << "iso-ir-100" | - | ||||||||||||
86 | << "csISOLatin1"; | - | ||||||||||||
87 | return list; executed 142 times by 6 tests: return list; Executed by:
| 142 | ||||||||||||
88 | } | - | ||||||||||||
89 | - | |||||||||||||
90 | - | |||||||||||||
91 | int QLatin1Codec::mibEnum() const | - | ||||||||||||
92 | { | - | ||||||||||||
93 | return 4; executed 36 times by 2 tests: return 4; Executed by:
| 36 | ||||||||||||
94 | } | - | ||||||||||||
95 | - | |||||||||||||
96 | - | |||||||||||||
97 | QLatin15Codec::~QLatin15Codec() | - | ||||||||||||
98 | { | - | ||||||||||||
99 | } | - | ||||||||||||
100 | - | |||||||||||||
101 | QString QLatin15Codec::convertToUnicode(const char* chars, int len, ConverterState *) const | - | ||||||||||||
102 | { | - | ||||||||||||
103 | if (chars == 0)
| 0 | ||||||||||||
104 | return QString(); never executed: return QString(); | 0 | ||||||||||||
105 | - | |||||||||||||
106 | QString str = QString::fromLatin1(chars, len); | - | ||||||||||||
107 | QChar *uc = str.data(); | - | ||||||||||||
108 | while(len--) {
| 0 | ||||||||||||
109 | switch(uc->unicode()) { | - | ||||||||||||
110 | case 0xa4: never executed: case 0xa4: | 0 | ||||||||||||
111 | *uc = 0x20ac; | - | ||||||||||||
112 | break; never executed: break; | 0 | ||||||||||||
113 | case 0xa6: never executed: case 0xa6: | 0 | ||||||||||||
114 | *uc = 0x0160; | - | ||||||||||||
115 | break; never executed: break; | 0 | ||||||||||||
116 | case 0xa8: never executed: case 0xa8: | 0 | ||||||||||||
117 | *uc = 0x0161; | - | ||||||||||||
118 | break; never executed: break; | 0 | ||||||||||||
119 | case 0xb4: never executed: case 0xb4: | 0 | ||||||||||||
120 | *uc = 0x017d; | - | ||||||||||||
121 | break; never executed: break; | 0 | ||||||||||||
122 | case 0xb8: never executed: case 0xb8: | 0 | ||||||||||||
123 | *uc = 0x017e; | - | ||||||||||||
124 | break; never executed: break; | 0 | ||||||||||||
125 | case 0xbc: never executed: case 0xbc: | 0 | ||||||||||||
126 | *uc = 0x0152; | - | ||||||||||||
127 | break; never executed: break; | 0 | ||||||||||||
128 | case 0xbd: never executed: case 0xbd: | 0 | ||||||||||||
129 | *uc = 0x0153; | - | ||||||||||||
130 | break; never executed: break; | 0 | ||||||||||||
131 | case 0xbe: never executed: case 0xbe: | 0 | ||||||||||||
132 | *uc = 0x0178; | - | ||||||||||||
133 | break; never executed: break; | 0 | ||||||||||||
134 | default: never executed: default: | 0 | ||||||||||||
135 | break; never executed: break; | 0 | ||||||||||||
136 | } | - | ||||||||||||
137 | uc++; | - | ||||||||||||
138 | } never executed: end of block | 0 | ||||||||||||
139 | return str; never executed: return str; | 0 | ||||||||||||
140 | } | - | ||||||||||||
141 | - | |||||||||||||
142 | QByteArray QLatin15Codec::convertFromUnicode(const QChar *in, int length, ConverterState *state) const | - | ||||||||||||
143 | { | - | ||||||||||||
144 | const char replacement = (state && state->flags & ConvertInvalidToNull) ? 0 : '?';
| 0 | ||||||||||||
145 | QByteArray r(length, Qt::Uninitialized); | - | ||||||||||||
146 | char *d = r.data(); | - | ||||||||||||
147 | int invalid = 0; | - | ||||||||||||
148 | for (int i = 0; i < length; ++i) {
| 0 | ||||||||||||
149 | uchar c; | - | ||||||||||||
150 | ushort uc = in[i].unicode(); | - | ||||||||||||
151 | if (uc < 0x0100) {
| 0 | ||||||||||||
152 | if (uc > 0xa3) {
| 0 | ||||||||||||
153 | switch(uc) { | - | ||||||||||||
154 | case 0xa4: never executed: case 0xa4: | 0 | ||||||||||||
155 | case 0xa6: never executed: case 0xa6: | 0 | ||||||||||||
156 | case 0xa8: never executed: case 0xa8: | 0 | ||||||||||||
157 | case 0xb4: never executed: case 0xb4: | 0 | ||||||||||||
158 | case 0xb8: never executed: case 0xb8: | 0 | ||||||||||||
159 | case 0xbc: never executed: case 0xbc: | 0 | ||||||||||||
160 | case 0xbd: never executed: case 0xbd: | 0 | ||||||||||||
161 | case 0xbe: never executed: case 0xbe: | 0 | ||||||||||||
162 | c = replacement; | - | ||||||||||||
163 | ++invalid; | - | ||||||||||||
164 | break; never executed: break; | 0 | ||||||||||||
165 | default: never executed: default: | 0 | ||||||||||||
166 | c = (unsigned char) uc; | - | ||||||||||||
167 | break; never executed: break; | 0 | ||||||||||||
168 | } | - | ||||||||||||
169 | } else { | - | ||||||||||||
170 | c = (unsigned char) uc; | - | ||||||||||||
171 | } never executed: end of block | 0 | ||||||||||||
172 | } else { | - | ||||||||||||
173 | if (uc == 0x20ac)
| 0 | ||||||||||||
174 | c = 0xa4; never executed: c = 0xa4; | 0 | ||||||||||||
175 | else if ((uc & 0xff00) == 0x0100) {
| 0 | ||||||||||||
176 | switch(uc) { | - | ||||||||||||
177 | case 0x0160: never executed: case 0x0160: | 0 | ||||||||||||
178 | c = 0xa6; | - | ||||||||||||
179 | break; never executed: break; | 0 | ||||||||||||
180 | case 0x0161: never executed: case 0x0161: | 0 | ||||||||||||
181 | c = 0xa8; | - | ||||||||||||
182 | break; never executed: break; | 0 | ||||||||||||
183 | case 0x017d: never executed: case 0x017d: | 0 | ||||||||||||
184 | c = 0xb4; | - | ||||||||||||
185 | break; never executed: break; | 0 | ||||||||||||
186 | case 0x017e: never executed: case 0x017e: | 0 | ||||||||||||
187 | c = 0xb8; | - | ||||||||||||
188 | break; never executed: break; | 0 | ||||||||||||
189 | case 0x0152: never executed: case 0x0152: | 0 | ||||||||||||
190 | c = 0xbc; | - | ||||||||||||
191 | break; never executed: break; | 0 | ||||||||||||
192 | case 0x0153: never executed: case 0x0153: | 0 | ||||||||||||
193 | c = 0xbd; | - | ||||||||||||
194 | break; never executed: break; | 0 | ||||||||||||
195 | case 0x0178: never executed: case 0x0178: | 0 | ||||||||||||
196 | c = 0xbe; | - | ||||||||||||
197 | break; never executed: break; | 0 | ||||||||||||
198 | default: never executed: default: | 0 | ||||||||||||
199 | c = replacement; | - | ||||||||||||
200 | ++invalid; | - | ||||||||||||
201 | } never executed: end of block | 0 | ||||||||||||
202 | } else { | - | ||||||||||||
203 | c = replacement; | - | ||||||||||||
204 | ++invalid; | - | ||||||||||||
205 | } never executed: end of block | 0 | ||||||||||||
206 | } | - | ||||||||||||
207 | d[i] = (char)c; | - | ||||||||||||
208 | } never executed: end of block | 0 | ||||||||||||
209 | if (state) {
| 0 | ||||||||||||
210 | state->remainingChars = 0; | - | ||||||||||||
211 | state->invalidChars += invalid; | - | ||||||||||||
212 | } never executed: end of block | 0 | ||||||||||||
213 | return r; never executed: return r; | 0 | ||||||||||||
214 | } | - | ||||||||||||
215 | - | |||||||||||||
216 | - | |||||||||||||
217 | QByteArray QLatin15Codec::name() const | - | ||||||||||||
218 | { | - | ||||||||||||
219 | return "ISO-8859-15"; never executed: return "ISO-8859-15"; | 0 | ||||||||||||
220 | } | - | ||||||||||||
221 | - | |||||||||||||
222 | QList<QByteArray> QLatin15Codec::aliases() const | - | ||||||||||||
223 | { | - | ||||||||||||
224 | QList<QByteArray> list; | - | ||||||||||||
225 | list << "latin9"; | - | ||||||||||||
226 | return list; never executed: return list; | 0 | ||||||||||||
227 | } | - | ||||||||||||
228 | - | |||||||||||||
229 | int QLatin15Codec::mibEnum() const | - | ||||||||||||
230 | { | - | ||||||||||||
231 | return 111; never executed: return 111; | 0 | ||||||||||||
232 | } | - | ||||||||||||
233 | - | |||||||||||||
234 | QT_END_NAMESPACE | - | ||||||||||||
235 | - | |||||||||||||
236 | #endif // QT_NO_TEXTCODEC | - | ||||||||||||
Source code | Switch to Preprocessed file |