ยปCore Development>Code coverage>Modules/cjkcodecs/_codecs_tw.c

Python code coverage for Modules/cjkcodecs/_codecs_tw.c

#countcontent
1n/a/*
2n/a * _codecs_tw.c: Codecs collection for Taiwan's encodings
3n/a *
4n/a * Written by Hye-Shik Chang <perky@FreeBSD.org>
5n/a */
6n/a
7n/a#include "cjkcodecs.h"
8n/a#include "mappings_tw.h"
9n/a
10n/a/*
11n/a * BIG5 codec
12n/a */
13n/a
14n/aENCODER(big5)
15n/a{
16n/a while (*inpos < inlen) {
17n/a Py_UCS4 c = INCHAR1;
18n/a DBCHAR code;
19n/a
20n/a if (c < 0x80) {
21n/a REQUIRE_OUTBUF(1);
22n/a **outbuf = (unsigned char)c;
23n/a NEXT(1, 1);
24n/a continue;
25n/a }
26n/a
27n/a if (c > 0xFFFF)
28n/a return 1;
29n/a
30n/a REQUIRE_OUTBUF(2);
31n/a
32n/a if (TRYMAP_ENC(big5, code, c))
33n/a ;
34n/a else
35n/a return 1;
36n/a
37n/a OUTBYTE1(code >> 8);
38n/a OUTBYTE2(code & 0xFF);
39n/a NEXT(1, 2);
40n/a }
41n/a
42n/a return 0;
43n/a}
44n/a
45n/aDECODER(big5)
46n/a{
47n/a while (inleft > 0) {
48n/a unsigned char c = INBYTE1;
49n/a Py_UCS4 decoded;
50n/a
51n/a if (c < 0x80) {
52n/a OUTCHAR(c);
53n/a NEXT_IN(1);
54n/a continue;
55n/a }
56n/a
57n/a REQUIRE_INBUF(2);
58n/a if (TRYMAP_DEC(big5, decoded, c, INBYTE2)) {
59n/a OUTCHAR(decoded);
60n/a NEXT_IN(2);
61n/a }
62n/a else return 1;
63n/a }
64n/a
65n/a return 0;
66n/a}
67n/a
68n/a
69n/a/*
70n/a * CP950 codec
71n/a */
72n/a
73n/aENCODER(cp950)
74n/a{
75n/a while (*inpos < inlen) {
76n/a Py_UCS4 c = INCHAR1;
77n/a DBCHAR code;
78n/a
79n/a if (c < 0x80) {
80n/a WRITEBYTE1((unsigned char)c);
81n/a NEXT(1, 1);
82n/a continue;
83n/a }
84n/a
85n/a if (c > 0xFFFF)
86n/a return 1;
87n/a
88n/a REQUIRE_OUTBUF(2);
89n/a if (TRYMAP_ENC(cp950ext, code, c))
90n/a ;
91n/a else if (TRYMAP_ENC(big5, code, c))
92n/a ;
93n/a else
94n/a return 1;
95n/a
96n/a OUTBYTE1(code >> 8);
97n/a OUTBYTE2(code & 0xFF);
98n/a NEXT(1, 2);
99n/a }
100n/a
101n/a return 0;
102n/a}
103n/a
104n/aDECODER(cp950)
105n/a{
106n/a while (inleft > 0) {
107n/a unsigned char c = INBYTE1;
108n/a Py_UCS4 decoded;
109n/a
110n/a if (c < 0x80) {
111n/a OUTCHAR(c);
112n/a NEXT_IN(1);
113n/a continue;
114n/a }
115n/a
116n/a REQUIRE_INBUF(2);
117n/a
118n/a if (TRYMAP_DEC(cp950ext, decoded, c, INBYTE2))
119n/a OUTCHAR(decoded);
120n/a else if (TRYMAP_DEC(big5, decoded, c, INBYTE2))
121n/a OUTCHAR(decoded);
122n/a else
123n/a return 1;
124n/a
125n/a NEXT_IN(2);
126n/a }
127n/a
128n/a return 0;
129n/a}
130n/a
131n/a
132n/a
133n/aBEGIN_MAPPINGS_LIST
134n/a MAPPING_ENCDEC(big5)
135n/a MAPPING_ENCDEC(cp950ext)
136n/aEND_MAPPINGS_LIST
137n/a
138n/aBEGIN_CODECS_LIST
139n/a CODEC_STATELESS(big5)
140n/a CODEC_STATELESS(cp950)
141n/aEND_CODECS_LIST
142n/a
143n/aI_AM_A_MODULE_FOR(tw)