codecs/qisciicodec.cpp

Source codeSwitch to Preprocessed file
LineSource CodeCoverage
1/**************************************************************************** -
2** -
3** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -
4** Contact: http://www.qt-project.org/legal -
5** -
6** This file is part of the QtCore module of the Qt Toolkit. -
7** -
8** $QT_BEGIN_LICENSE:LGPL$ -
9** Commercial License Usage -
10** Licensees holding valid commercial Qt licenses may use this file in -
11** accordance with the commercial license agreement provided with the -
12** Software or, alternatively, in accordance with the terms contained in -
13** a written agreement between you and Digia. For licensing terms and -
14** conditions see http://qt.digia.com/licensing. For further information -
15** use the contact form at http://qt.digia.com/contact-us. -
16** -
17** GNU Lesser General Public License Usage -
18** Alternatively, this file may be used under the terms of the GNU Lesser -
19** General Public License version 2.1 as published by the Free Software -
20** Foundation and appearing in the file LICENSE.LGPL included in the -
21** packaging of this file. Please review the following information to -
22** ensure the GNU Lesser General Public License version 2.1 requirements -
23** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -
24** -
25** In addition, as a special exception, Digia gives you certain additional -
26** rights. These rights are described in the Digia Qt LGPL Exception -
27** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -
28** -
29** GNU General Public License Usage -
30** Alternatively, this file may be used under the terms of the GNU -
31** General Public License version 3.0 as published by the Free Software -
32** Foundation and appearing in the file LICENSE.GPL included in the -
33** packaging of this file. Please review the following information to -
34** ensure the GNU General Public License version 3.0 requirements will be -
35** met: http://www.gnu.org/copyleft/gpl.html. -
36** -
37** -
38** $QT_END_LICENSE$ -
39** -
40****************************************************************************/ -
41#include "qisciicodec_p.h" -
42#include "qtextcodec_p.h" -
43#include "qlist.h" -
44 -
45#ifndef QT_NO_CODECS -
46 -
47QT_BEGIN_NAMESPACE -
48 -
49/*! -
50 \class QIsciiCodec -
51 \inmodule QtCore -
52 \brief The QIsciiCodec class provides conversion to and from the ISCII encoding. -
53 -
54 \internal -
55*/ -
56 -
57 -
58struct Codecs { -
59 const char name[10]; -
60 ushort base; -
61}; -
62 -
63static const Codecs codecs [] = { -
64 { "iscii-dev", 0x900 }, -
65 { "iscii-bng", 0x980 }, -
66 { "iscii-pnj", 0xa00 }, -
67 { "iscii-gjr", 0xa80 }, -
68 { "iscii-ori", 0xb00 }, -
69 { "iscii-tml", 0xb80 }, -
70 { "iscii-tlg", 0xc00 }, -
71 { "iscii-knd", 0xc80 }, -
72 { "iscii-mlm", 0xd00 } -
73}; -
74 -
75QTextCodec *QIsciiCodec::create(const char *name) -
76{ -
77 for (int i = 0; i < 9; ++i) {
partially evaluated: i < 9
TRUEFALSE
yes
Evaluation Count:45
no
Evaluation Count:0
0-45
78 if (qTextCodecNameMatch(name, codecs[i].name))
evaluated: qTextCodecNameMatch(name, codecs[i].name)
TRUEFALSE
yes
Evaluation Count:9
yes
Evaluation Count:36
9-36
79 return new QIsciiCodec(i);
executed: return new QIsciiCodec(i);
Execution Count:9
9
80 }
executed: }
Execution Count:36
36
81 return 0;
never executed: return 0;
0
82} -
83 -
84QIsciiCodec::~QIsciiCodec() -
85{ -
86} -
87 -
88QByteArray QIsciiCodec::name() const -
89{ -
90 return codecs[idx].name;
executed: return codecs[idx].name;
Execution Count:1557
1557
91} -
92 -
93int QIsciiCodec::mibEnum() const -
94{ -
95 /* There is no MIBEnum for Iscii */ -
96 return -3000-idx;
never executed: return -3000-idx;
0
97} -
98 -
99static const uchar inv = 0xFF; -
100 -
101/* iscii range from 0xa0 - 0xff */ -
102static const uchar iscii_to_uni_table[0x60] = { -
103 0x00, 0x01, 0x02, 0x03, -
104 0x05, 0x06, 0x07, 0x08, -
105 0x09, 0x0a, 0x0b, 0x0e, -
106 0x0f, 0x20, 0x0d, 0x12, -
107 -
108 0x13, 0x14, 0x11, 0x15, -
109 0x16, 0x17, 0x18, 0x19, -
110 0x1a, 0x1b, 0x1c, 0x1d, -
111 0x1e, 0x1f, 0x20, 0x21, -
112 -
113 0x22, 0x23, 0x24, 0x25, -
114 0x26, 0x27, 0x28, 0x29, -
115 0x2a, 0x2b, 0x2c, 0x2d, -
116 0x2e, 0x2f, 0x5f, 0x30, -
117 -
118 0x31, 0x32, 0x33, 0x34, -
119 0x35, 0x36, 0x37, 0x38, -
120 0x39, inv, 0x3e, 0x3f, -
121 0x40, 0x41, 0x42, 0x43, -
122 -
123 0x46, 0x47, 0x48, 0x45, -
124 0x4a, 0x4b, 0x4c, 0x49, -
125 0x4d, 0x3c, 0x64, 0x00, -
126 0x00, 0x00, 0x00, 0x00, -
127 -
128 0x00, 0x66, 0x67, 0x68, -
129 0x69, 0x6a, 0x6b, 0x6c, -
130 0x6d, 0x6e, 0x6f, 0x00, -
131 0x00, 0x00, 0x00, 0x00 -
132}; -
133 -
134static const uchar uni_to_iscii_table[0x80] = { -
135 0x00, 0xa1, 0xa2, 0xa3, -
136 0x00, 0xa4, 0xa5, 0xa6, -
137 0xa7, 0xa8, 0xa9, 0xaa, -
138 0x00, 0xae, 0xab, 0xac, -
139 -
140 0xad, 0xb2, 0xaf, 0xb0, -
141 0xb1, 0xb3, 0xb4, 0xb5, -
142 0xb6, 0xb7, 0xb8, 0xb9, -
143 0xba, 0xbb, 0xbc, 0xbd, -
144 -
145 0xbe, 0xbf, 0xc0, 0xc1, -
146 0xc2, 0xc3, 0xc4, 0xc5, -
147 0xc6, 0xc7, 0xc8, 0xc9, -
148 0xca, 0xcb, 0xcc, 0xcd, -
149 -
150 0xcf, 0xd0, 0xd1, 0xd2, -
151 0xd3, 0xd4, 0xd5, 0xd6, -
152 0xd7, 0xd8, 0x00, 0x00, -
153 0xe9, 0x00, 0xda, 0xdb, -
154 -
155 0xdc, 0xdd, 0xde, 0xdf, -
156 0x00, 0xe3, 0xe0, 0xe1, -
157 0xe2, 0xe7, 0xe4, 0xe5, -
158 0xe6, 0xe8, 0x00, 0x00, -
159 -
160 0x00, 0x00, 0x00, 0x00, -
161 0x00, 0x00, 0x00, 0x00, -
162 0x01, 0x02, 0x03, 0x04, // decomposable into the uc codes listed here + nukta -
163 0x05, 0x06, 0x07, 0xce, -
164 -
165 0x00, 0x00, 0x00, 0x00, -
166 0xea, 0x08, 0xf1, 0xf2, -
167 0xf3, 0xf4, 0xf5, 0xf6, -
168 0xf7, 0xf8, 0xf9, 0xfa, -
169 -
170 0x00, 0x00, 0x00, 0x00, -
171 0x00, 0x00, 0x00, 0x00, -
172 0x00, 0x00, 0x00, 0x00, -
173 0x00, 0x00, 0x00, 0x00 -
174}; -
175 -
176static const uchar uni_to_iscii_pairs[] = { -
177 0x00, 0x00, -
178 0x15, 0x3c, // 0x958 -
179 0x16, 0x3c, // 0x959 -
180 0x17, 0x3c, // 0x95a -
181 0x1c, 0x3c, // 0x95b -
182 0x21, 0x3c, // 0x95c -
183 0x22, 0x3c, // 0x95d -
184 0x2b, 0x3c, // 0x95e -
185 0x64, 0x64 // 0x965 -
186}; -
187 -
188 -
189QByteArray QIsciiCodec::convertFromUnicode(const QChar *uc, int len, ConverterState *state) const -
190{ -
191 char replacement = '?';
executed (the execution status of this line is deduced): char replacement = '?';
-
192 bool halant = false;
executed (the execution status of this line is deduced): bool halant = false;
-
193 if (state) {
partially evaluated: state
TRUEFALSE
yes
Evaluation Count:1440
no
Evaluation Count:0
0-1440
194 if (state->flags & ConvertInvalidToNull)
partially evaluated: state->flags & ConvertInvalidToNull
TRUEFALSE
yes
Evaluation Count:1440
no
Evaluation Count:0
0-1440
195 replacement = 0;
executed: replacement = 0;
Execution Count:1440
1440
196 halant = state->state_data[0];
executed (the execution status of this line is deduced): halant = state->state_data[0];
-
197 }
executed: }
Execution Count:1440
1440
198 int invalid = 0;
executed (the execution status of this line is deduced): int invalid = 0;
-
199 -
200 QByteArray result(2 * len, Qt::Uninitialized); //worst case
executed (the execution status of this line is deduced): QByteArray result(2 * len, Qt::Uninitialized);
-
201 -
202 uchar *ch = reinterpret_cast<uchar *>(result.data());
executed (the execution status of this line is deduced): uchar *ch = reinterpret_cast<uchar *>(result.data());
-
203 -
204 const int base = codecs[idx].base;
executed (the execution status of this line is deduced): const int base = codecs[idx].base;
-
205 -
206 for (int i =0; i < len; ++i) {
evaluated: i < len
TRUEFALSE
yes
Evaluation Count:2862
yes
Evaluation Count:1440
1440-2862
207 const ushort codePoint = uc[i].unicode();
executed (the execution status of this line is deduced): const ushort codePoint = uc[i].unicode();
-
208 -
209 /* The low 7 bits of ISCII is plain ASCII. However, we go all the -
210 * way up to 0xA0 such that we can roundtrip with convertToUnicode()'s -
211 * behavior. */ -
212 if(codePoint < 0xA0) {
partially evaluated: codePoint < 0xA0
TRUEFALSE
yes
Evaluation Count:2862
no
Evaluation Count:0
0-2862
213 *ch++ = static_cast<uchar>(codePoint);
executed (the execution status of this line is deduced): *ch++ = static_cast<uchar>(codePoint);
-
214 continue;
executed: continue;
Execution Count:2862
2862
215 } -
216 -
217 const int pos = codePoint - base;
never executed (the execution status of this line is deduced): const int pos = codePoint - base;
-
218 if (pos > 0 && pos < 0x80) {
never evaluated: pos > 0
never evaluated: pos < 0x80
0
219 uchar iscii = uni_to_iscii_table[pos];
never executed (the execution status of this line is deduced): uchar iscii = uni_to_iscii_table[pos];
-
220 if (iscii > 0x80) {
never evaluated: iscii > 0x80
0
221 *ch++ = iscii;
never executed (the execution status of this line is deduced): *ch++ = iscii;
-
222 } else if (iscii) {
never executed: }
never evaluated: iscii
0
223 const uchar *pair = uni_to_iscii_pairs + 2*iscii;
never executed (the execution status of this line is deduced): const uchar *pair = uni_to_iscii_pairs + 2*iscii;
-
224 *ch++ = *pair++;
never executed (the execution status of this line is deduced): *ch++ = *pair++;
-
225 *ch++ = *pair++;
never executed (the execution status of this line is deduced): *ch++ = *pair++;
-
226 } else {
never executed: }
0
227 *ch++ = replacement;
never executed (the execution status of this line is deduced): *ch++ = replacement;
-
228 ++invalid;
never executed (the execution status of this line is deduced): ++invalid;
-
229 }
never executed: }
0
230 } else { -
231 if (uc[i].unicode() == 0x200c) { // ZWNJ
never evaluated: uc[i].unicode() == 0x200c
0
232 if (halant)
never evaluated: halant
0
233 // Consonant Halant ZWNJ -> Consonant Halant Halant -
234 *ch++ = 0xe8;
never executed: *ch++ = 0xe8;
0
235 } else if (uc[i].unicode() == 0x200d) { // ZWJ
never executed: }
never evaluated: uc[i].unicode() == 0x200d
0
236 if (halant)
never evaluated: halant
0
237 // Consonant Halant ZWJ -> Consonant Halant Nukta -
238 *ch++ = 0xe9;
never executed: *ch++ = 0xe9;
0
239 } else {
never executed: }
0
240 *ch++ = replacement;
never executed (the execution status of this line is deduced): *ch++ = replacement;
-
241 ++invalid;
never executed (the execution status of this line is deduced): ++invalid;
-
242 }
never executed: }
0
243 } -
244 halant = (pos == 0x4d);
never executed (the execution status of this line is deduced): halant = (pos == 0x4d);
-
245 }
never executed: }
0
246 result.truncate(ch - (uchar *)result.data());
executed (the execution status of this line is deduced): result.truncate(ch - (uchar *)result.data());
-
247 -
248 if (state) {
partially evaluated: state
TRUEFALSE
yes
Evaluation Count:1440
no
Evaluation Count:0
0-1440
249 state->invalidChars += invalid;
executed (the execution status of this line is deduced): state->invalidChars += invalid;
-
250 state->state_data[0] = halant;
executed (the execution status of this line is deduced): state->state_data[0] = halant;
-
251 }
executed: }
Execution Count:1440
1440
252 return result;
executed: return result;
Execution Count:1440
1440
253} -
254 -
255QString QIsciiCodec::convertToUnicode(const char* chars, int len, ConverterState *state) const -
256{ -
257 bool halant = false;
never executed (the execution status of this line is deduced): bool halant = false;
-
258 if (state) {
never evaluated: state
0
259 halant = state->state_data[0];
never executed (the execution status of this line is deduced): halant = state->state_data[0];
-
260 }
never executed: }
0
261 -
262 QString result(len, Qt::Uninitialized);
never executed (the execution status of this line is deduced): QString result(len, Qt::Uninitialized);
-
263 QChar *uc = result.data();
never executed (the execution status of this line is deduced): QChar *uc = result.data();
-
264 -
265 const int base = codecs[idx].base;
never executed (the execution status of this line is deduced): const int base = codecs[idx].base;
-
266 -
267 for (int i = 0; i < len; ++i) {
never evaluated: i < len
0
268 ushort ch = (uchar) chars[i];
never executed (the execution status of this line is deduced): ushort ch = (uchar) chars[i];
-
269 if (ch < 0xa0)
never evaluated: ch < 0xa0
0
270 *uc++ = ch;
never executed: *uc++ = ch;
0
271 else { -
272 ushort c = iscii_to_uni_table[ch - 0xa0];
never executed (the execution status of this line is deduced): ushort c = iscii_to_uni_table[ch - 0xa0];
-
273 if (halant && (c == inv || c == 0xe9)) {
never evaluated: halant
never evaluated: c == inv
never evaluated: c == 0xe9
0
274 // Consonant Halant inv -> Consonant Halant ZWJ -
275 // Consonant Halant Nukta -> Consonant Halant ZWJ -
276 *uc++ = QChar(0x200d);
never executed (the execution status of this line is deduced): *uc++ = QChar(0x200d);
-
277 } else if (halant && c == 0xe8) {
never executed: }
never evaluated: halant
never evaluated: c == 0xe8
0
278 // Consonant Halant Halant -> Consonant Halant ZWNJ -
279 *uc++ = QChar(0x200c);
never executed (the execution status of this line is deduced): *uc++ = QChar(0x200c);
-
280 } else {
never executed: }
0
281 *uc++ = QChar(c+base);
never executed (the execution status of this line is deduced): *uc++ = QChar(c+base);
-
282 }
never executed: }
0
283 } -
284 halant = ((uchar)chars[i] == 0xe8);
never executed (the execution status of this line is deduced): halant = ((uchar)chars[i] == 0xe8);
-
285 }
never executed: }
0
286 result.resize(uc - result.unicode());
never executed (the execution status of this line is deduced): result.resize(uc - result.unicode());
-
287 -
288 if (state) {
never evaluated: state
0
289 state->state_data[0] = halant;
never executed (the execution status of this line is deduced): state->state_data[0] = halant;
-
290 }
never executed: }
0
291 return result;
never executed: return result;
0
292} -
293 -
294QT_END_NAMESPACE -
295 -
296#endif // QT_NO_CODECS -
297 -
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial