qisciicodec.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/corelib/codecs/qisciicodec.cpp
Switch to Source codePreprocessed file
LineSourceCount
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 < 9Description
TRUEevaluated 45 times by 1 test
Evaluated by:
  • tst_QTextCodec
FALSEnever evaluated
; ++i) {
0-45
25 if (qTextCodecNameMatch(name, codecs[i].name)
qTextCodecName...odecs[i].name)Description
TRUEevaluated 9 times by 1 test
Evaluated by:
  • tst_QTextCodec
FALSEevaluated 36 times by 1 test
Evaluated by:
  • tst_QTextCodec
)
9-36
26 return
executed 9 times by 1 test: return new QIsciiCodec(i);
Executed by:
  • tst_QTextCodec
new QIsciiCodec(i);
executed 9 times by 1 test: return new QIsciiCodec(i);
Executed by:
  • tst_QTextCodec
9
27 }
executed 36 times by 1 test: end of block
Executed by:
  • tst_QTextCodec
36
28 return
never executed: return 0;
0;
never executed: return 0;
0
29}-
30-
31QIsciiCodec::~QIsciiCodec()-
32{-
33}-
34-
35QByteArray QIsciiCodec::name() const-
36{-
37 return
executed 1656 times by 1 test: return codecs[idx].name;
Executed by:
  • tst_QTextCodec
codecs[idx].name;
executed 1656 times by 1 test: return codecs[idx].name;
Executed by:
  • tst_QTextCodec
1656
38}-
39-
40int QIsciiCodec::mibEnum() const-
41{-
42-
43 return
never executed: return -3000-idx;
-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
stateDescription
TRUEevaluated 1440 times by 1 test
Evaluated by:
  • tst_QTextCodec
FALSEnever evaluated
) {
0-1440
141 if (state->flags & ConvertInvalidToNull
state->flags &...tInvalidToNullDescription
TRUEevaluated 1440 times by 1 test
Evaluated by:
  • tst_QTextCodec
FALSEnever evaluated
)
0-1440
142 replacement = 0;
executed 1440 times by 1 test: replacement = 0;
Executed by:
  • tst_QTextCodec
1440
143 halant = state->state_data[0];-
144 }
executed 1440 times by 1 test: end of block
Executed by:
  • tst_QTextCodec
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 < lenDescription
TRUEevaluated 2862 times by 1 test
Evaluated by:
  • tst_QTextCodec
FALSEevaluated 1440 times by 1 test
Evaluated by:
  • tst_QTextCodec
; ++i) {
1440-2862
154 const ushort codePoint = uc[i].unicode();-
155-
156-
157-
158-
159 if(codePoint < 0xA0
codePoint < 0xA0Description
TRUEevaluated 2862 times by 1 test
Evaluated by:
  • tst_QTextCodec
FALSEnever evaluated
) {
0-2862
160 *ch++ = static_cast<uchar>(codePoint);-
161 continue;
executed 2862 times by 1 test: continue;
Executed by:
  • tst_QTextCodec
2862
162 }-
163-
164 const int pos = codePoint - base;-
165 if (pos > 0
pos > 0Description
TRUEnever evaluated
FALSEnever evaluated
&& pos < 0x80
pos < 0x80Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
166 uchar iscii = uni_to_iscii_table[pos];-
167 if (iscii > 0x80
iscii > 0x80Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
168 *ch++ = iscii;-
169 }
never executed: end of block
else if (iscii
isciiDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
170 ((!((2 * iscii) < (sizeof(uni_to_iscii_pairs) / sizeof(uni_to_iscii_pairs[0])))) ? qt_assert("(2 * iscii) < (sizeof(uni_to_iscii_pairs) / sizeof(uni_to_iscii_pairs[0]))",__FILE__,221) : qt_noop());-
171 const uchar *pair = uni_to_iscii_pairs + 2*iscii;-
172 *ch++ = *pair++;-
173 *ch++ = *pair++;-
174 }
never executed: end of block
else {
0
175 *ch++ = replacement;-
176 ++invalid;-
177 }
never executed: end of block
0
178 } else {-
179 if (uc[i].unicode() == 0x200c
uc[i].unicode() == 0x200cDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
180 if (halant
halantDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
181-
182 *
never executed: *ch++ = 0xe8;
ch++ = 0xe8;
never executed: *ch++ = 0xe8;
0
183 }
never executed: end of block
else if (uc[i].unicode() == 0x200d
uc[i].unicode() == 0x200dDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
184 if (halant
halantDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
185-
186 *
never executed: *ch++ = 0xe9;
ch++ = 0xe9;
never executed: *ch++ = 0xe9;
0
187 }
never executed: end of block
else {
0
188 *ch++ = replacement;-
189 ++invalid;-
190 }
never executed: end of block
0
191 }-
192 halant = (pos == 0x4d);-
193 }
never executed: end of block
0
194 result.truncate(ch - (uchar *)result.data());-
195-
196 if (state
stateDescription
TRUEevaluated 1440 times by 1 test
Evaluated by:
  • tst_QTextCodec
FALSEnever evaluated
) {
0-1440
197 state->invalidChars += invalid;-
198 state->state_data[0] = halant;-
199 }
executed 1440 times by 1 test: end of block
Executed by:
  • tst_QTextCodec
1440
200 return
executed 1440 times by 1 test: return result;
Executed by:
  • tst_QTextCodec
result;
executed 1440 times by 1 test: return result;
Executed by:
  • tst_QTextCodec
1440
201}-
202-
203QString QIsciiCodec::convertToUnicode(const char* chars, int len, ConverterState *state) const-
204{-
205 bool halant = false;-
206 if (state
stateDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
207 halant = state->state_data[0];-
208 }
never executed: end of block
0
209-
210 QString result(len, Qt::Uninitialized);-
211 QChar *uc = result.data();-
212-
213 const int base = codecs[idx].base;-
214-
215 for (int i = 0; i < len
i < lenDescription
TRUEnever evaluated
FALSEnever evaluated
; ++i) {
0
216 ushort ch = (uchar) chars[i];-
217 if (ch < 0xa0
ch < 0xa0Description
TRUEnever evaluated
FALSEnever evaluated
)
0
218 *
never executed: *uc++ = ch;
uc++ = ch;
never executed: *uc++ = ch;
0
219 else {-
220 ushort c = iscii_to_uni_table[ch - 0xa0];-
221 if (halant
halantDescription
TRUEnever evaluated
FALSEnever evaluated
&& (c == inv
c == invDescription
TRUEnever evaluated
FALSEnever evaluated
|| c == 0xe9
c == 0xe9Description
TRUEnever evaluated
FALSEnever evaluated
)) {
0
222-
223-
224 *uc++ = QChar(0x200d);-
225 }
never executed: end of block
else if (halant
halantDescription
TRUEnever evaluated
FALSEnever evaluated
&& c == 0xe8
c == 0xe8Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
226-
227 *uc++ = QChar(0x200c);-
228 }
never executed: end of block
else {
0
229 *uc++ = QChar(c+base);-
230 }
never executed: end of block
0
231 }-
232 halant = ((uchar)chars[i] == 0xe8);-
233 }
never executed: end of block
0
234 result.resize(uc - result.unicode());-
235-
236 if (state
stateDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
237 state->state_data[0] = halant;-
238 }
never executed: end of block
0
239 return
never executed: return result;
result;
never executed: return result;
0
240}-
241-
242-
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9