codecs/qisciicodec.cpp

Switch to Source codePreprocessed file
LineSource CodeCoverage
1 -
2 -
3 -
4 -
5struct Codecs { -
6 const char name[10]; -
7 ushort base; -
8}; -
9 -
10static const Codecs codecs [] = { -
11 { "iscii-dev", 0x900 }, -
12 { "iscii-bng", 0x980 }, -
13 { "iscii-pnj", 0xa00 }, -
14 { "iscii-gjr", 0xa80 }, -
15 { "iscii-ori", 0xb00 }, -
16 { "iscii-tml", 0xb80 }, -
17 { "iscii-tlg", 0xc00 }, -
18 { "iscii-knd", 0xc80 }, -
19 { "iscii-mlm", 0xd00 } -
20}; -
21 -
22QTextCodec *QIsciiCodec::create(const char *name) -
23{ -
24 for (int i = 0; i < 9; ++i) {
partially evaluated: i < 9
TRUEFALSE
yes
Evaluation Count:45
no
Evaluation Count:0
0-45
25 if (qTextCodecNameMatch(name, codecs[i].name))
evaluated: qTextCodecNameMatch(name, codecs[i].name)
TRUEFALSE
yes
Evaluation Count:9
yes
Evaluation Count:36
9-36
26 return new QIsciiCodec(i);
executed: return new QIsciiCodec(i);
Execution Count:9
9
27 }
executed: }
Execution Count:36
36
28 return 0;
never executed: return 0;
0
29} -
30 -
31QIsciiCodec::~QIsciiCodec() -
32{ -
33} -
34 -
35QByteArray QIsciiCodec::name() const -
36{ -
37 return codecs[idx].name;
executed: return codecs[idx].name;
Execution Count:1557
1557
38} -
39 -
40int QIsciiCodec::mibEnum() const -
41{ -
42 -
43 return -3000-idx;
never executed: return -3000-idx;
0
44} -
45 -
46static const uchar inv = 0xFF; -
47 -
48 -
49static const uchar iscii_to_uni_table[0x60] = { -
50 0x00, 0x01, 0x02, 0x03, -
51 0x05, 0x06, 0x07, 0x08, -
52 0x09, 0x0a, 0x0b, 0x0e, -
53 0x0f, 0x20, 0x0d, 0x12, -
54 -
55 0x13, 0x14, 0x11, 0x15, -
56 0x16, 0x17, 0x18, 0x19, -
57 0x1a, 0x1b, 0x1c, 0x1d, -
58 0x1e, 0x1f, 0x20, 0x21, -
59 -
60 0x22, 0x23, 0x24, 0x25, -
61 0x26, 0x27, 0x28, 0x29, -
62 0x2a, 0x2b, 0x2c, 0x2d, -
63 0x2e, 0x2f, 0x5f, 0x30, -
64 -
65 0x31, 0x32, 0x33, 0x34, -
66 0x35, 0x36, 0x37, 0x38, -
67 0x39, inv, 0x3e, 0x3f, -
68 0x40, 0x41, 0x42, 0x43, -
69 -
70 0x46, 0x47, 0x48, 0x45, -
71 0x4a, 0x4b, 0x4c, 0x49, -
72 0x4d, 0x3c, 0x64, 0x00, -
73 0x00, 0x00, 0x00, 0x00, -
74 -
75 0x00, 0x66, 0x67, 0x68, -
76 0x69, 0x6a, 0x6b, 0x6c, -
77 0x6d, 0x6e, 0x6f, 0x00, -
78 0x00, 0x00, 0x00, 0x00 -
79}; -
80 -
81static const uchar uni_to_iscii_table[0x80] = { -
82 0x00, 0xa1, 0xa2, 0xa3, -
83 0x00, 0xa4, 0xa5, 0xa6, -
84 0xa7, 0xa8, 0xa9, 0xaa, -
85 0x00, 0xae, 0xab, 0xac, -
86 -
87 0xad, 0xb2, 0xaf, 0xb0, -
88 0xb1, 0xb3, 0xb4, 0xb5, -
89 0xb6, 0xb7, 0xb8, 0xb9, -
90 0xba, 0xbb, 0xbc, 0xbd, -
91 -
92 0xbe, 0xbf, 0xc0, 0xc1, -
93 0xc2, 0xc3, 0xc4, 0xc5, -
94 0xc6, 0xc7, 0xc8, 0xc9, -
95 0xca, 0xcb, 0xcc, 0xcd, -
96 -
97 0xcf, 0xd0, 0xd1, 0xd2, -
98 0xd3, 0xd4, 0xd5, 0xd6, -
99 0xd7, 0xd8, 0x00, 0x00, -
100 0xe9, 0x00, 0xda, 0xdb, -
101 -
102 0xdc, 0xdd, 0xde, 0xdf, -
103 0x00, 0xe3, 0xe0, 0xe1, -
104 0xe2, 0xe7, 0xe4, 0xe5, -
105 0xe6, 0xe8, 0x00, 0x00, -
106 -
107 0x00, 0x00, 0x00, 0x00, -
108 0x00, 0x00, 0x00, 0x00, -
109 0x01, 0x02, 0x03, 0x04, -
110 0x05, 0x06, 0x07, 0xce, -
111 -
112 0x00, 0x00, 0x00, 0x00, -
113 0xea, 0x08, 0xf1, 0xf2, -
114 0xf3, 0xf4, 0xf5, 0xf6, -
115 0xf7, 0xf8, 0xf9, 0xfa, -
116 -
117 0x00, 0x00, 0x00, 0x00, -
118 0x00, 0x00, 0x00, 0x00, -
119 0x00, 0x00, 0x00, 0x00, -
120 0x00, 0x00, 0x00, 0x00 -
121}; -
122 -
123static const uchar uni_to_iscii_pairs[] = { -
124 0x00, 0x00, -
125 0x15, 0x3c, -
126 0x16, 0x3c, -
127 0x17, 0x3c, -
128 0x1c, 0x3c, -
129 0x21, 0x3c, -
130 0x22, 0x3c, -
131 0x2b, 0x3c, -
132 0x64, 0x64 -
133}; -
134 -
135 -
136QByteArray QIsciiCodec::convertFromUnicode(const QChar *uc, int len, ConverterState *state) const -
137{ -
138 char replacement = '?'; -
139 bool halant = false; -
140 if (state) {
partially evaluated: state
TRUEFALSE
yes
Evaluation Count:1440
no
Evaluation Count:0
0-1440
141 if (state->flags & ConvertInvalidToNull)
partially evaluated: state->flags & ConvertInvalidToNull
TRUEFALSE
yes
Evaluation Count:1440
no
Evaluation Count:0
0-1440
142 replacement = 0;
executed: replacement = 0;
Execution Count:1440
1440
143 halant = state->state_data[0]; -
144 }
executed: }
Execution Count:1440
1440
145 int invalid = 0; -
146 -
147 QByteArray result(2 * len, Qt::Uninitialized); -
148 -
149 uchar *ch = reinterpret_cast<uchar *>(result.data()); -
150 -
151 const int base = codecs[idx].base; -
152 -
153 for (int i =0; i < len; ++i) {
evaluated: i < len
TRUEFALSE
yes
Evaluation Count:2862
yes
Evaluation Count:1440
1440-2862
154 const ushort codePoint = uc[i].unicode(); -
155 -
156 -
157 -
158 -
159 if(codePoint < 0xA0) {
partially evaluated: codePoint < 0xA0
TRUEFALSE
yes
Evaluation Count:2862
no
Evaluation Count:0
0-2862
160 *ch++ = static_cast<uchar>(codePoint); -
161 continue;
executed: continue;
Execution Count:2862
2862
162 } -
163 -
164 const int pos = codePoint - base; -
165 if (pos > 0 && pos < 0x80) {
never evaluated: pos > 0
never evaluated: pos < 0x80
0
166 uchar iscii = uni_to_iscii_table[pos]; -
167 if (iscii > 0x80) {
never evaluated: iscii > 0x80
0
168 *ch++ = iscii; -
169 } else if (iscii) {
never evaluated: iscii
never executed: }
0
170 const uchar *pair = uni_to_iscii_pairs + 2*iscii; -
171 *ch++ = *pair++; -
172 *ch++ = *pair++; -
173 } else {
never executed: }
0
174 *ch++ = replacement; -
175 ++invalid; -
176 }
never executed: }
0
177 } else { -
178 if (uc[i].unicode() == 0x200c) {
never evaluated: uc[i].unicode() == 0x200c
0
179 if (halant)
never evaluated: halant
0
180 -
181 *ch++ = 0xe8;
never executed: *ch++ = 0xe8;
0
182 } else if (uc[i].unicode() == 0x200d) {
never executed: }
never evaluated: uc[i].unicode() == 0x200d
0
183 if (halant)
never evaluated: halant
0
184 -
185 *ch++ = 0xe9;
never executed: *ch++ = 0xe9;
0
186 } else {
never executed: }
0
187 *ch++ = replacement; -
188 ++invalid; -
189 }
never executed: }
0
190 } -
191 halant = (pos == 0x4d); -
192 }
never executed: }
0
193 result.truncate(ch - (uchar *)result.data()); -
194 -
195 if (state) {
partially evaluated: state
TRUEFALSE
yes
Evaluation Count:1440
no
Evaluation Count:0
0-1440
196 state->invalidChars += invalid; -
197 state->state_data[0] = halant; -
198 }
executed: }
Execution Count:1440
1440
199 return result;
executed: return result;
Execution Count:1440
1440
200} -
201 -
202QString QIsciiCodec::convertToUnicode(const char* chars, int len, ConverterState *state) const -
203{ -
204 bool halant = false; -
205 if (state) {
never evaluated: state
0
206 halant = state->state_data[0]; -
207 }
never executed: }
0
208 -
209 QString result(len, Qt::Uninitialized); -
210 QChar *uc = result.data(); -
211 -
212 const int base = codecs[idx].base; -
213 -
214 for (int i = 0; i < len; ++i) {
never evaluated: i < len
0
215 ushort ch = (uchar) chars[i]; -
216 if (ch < 0xa0)
never evaluated: ch < 0xa0
0
217 *uc++ = ch;
never executed: *uc++ = ch;
0
218 else { -
219 ushort c = iscii_to_uni_table[ch - 0xa0]; -
220 if (halant && (c == inv || c == 0xe9)) {
never evaluated: halant
never evaluated: c == inv
never evaluated: c == 0xe9
0
221 -
222 -
223 *uc++ = QChar(0x200d); -
224 } else if (halant && c == 0xe8) {
never executed: }
never evaluated: halant
never evaluated: c == 0xe8
0
225 -
226 *uc++ = QChar(0x200c); -
227 } else {
never executed: }
0
228 *uc++ = QChar(c+base); -
229 }
never executed: }
0
230 } -
231 halant = ((uchar)chars[i] == 0xe8); -
232 }
never executed: }
0
233 result.resize(uc - result.unicode()); -
234 -
235 if (state) {
never evaluated: state
0
236 state->state_data[0] = halant; -
237 }
never executed: }
0
238 return result;
never executed: return result;
0
239} -
240 -
241 -
242 -
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial