source: python/trunk/Modules/cjkcodecs/_codecs_tw.c

Last change on this file was 391, checked in by dmik, 11 years ago

python: Merge vendor 2.7.6 to trunk.

  • Property svn:eol-style set to native
File size: 2.0 KB
Line 
1/*
2 * _codecs_tw.c: Codecs collection for Taiwan's encodings
3 *
4 * Written by Hye-Shik Chang <perky@FreeBSD.org>
5 */
6
7#include "cjkcodecs.h"
8#include "mappings_tw.h"
9
10/*
11 * BIG5 codec
12 */
13
14ENCODER(big5)
15{
16 while (inleft > 0) {
17 Py_UNICODE c = **inbuf;
18 DBCHAR code;
19
20 if (c < 0x80) {
21 REQUIRE_OUTBUF(1)
22 **outbuf = (unsigned char)c;
23 NEXT(1, 1)
24 continue;
25 }
26 UCS4INVALID(c)
27
28 REQUIRE_OUTBUF(2)
29
30 TRYMAP_ENC(big5, code, c);
31 else return 1;
32
33 OUT1(code >> 8)
34 OUT2(code & 0xFF)
35 NEXT(1, 2)
36 }
37
38 return 0;
39}
40
41DECODER(big5)
42{
43 while (inleft > 0) {
44 unsigned char c = IN1;
45
46 REQUIRE_OUTBUF(1)
47
48 if (c < 0x80) {
49 OUT1(c)
50 NEXT(1, 1)
51 continue;
52 }
53
54 REQUIRE_INBUF(2)
55 TRYMAP_DEC(big5, **outbuf, c, IN2) {
56 NEXT(2, 1)
57 }
58 else return 2;
59 }
60
61 return 0;
62}
63
64
65/*
66 * CP950 codec
67 */
68
69ENCODER(cp950)
70{
71 while (inleft > 0) {
72 Py_UNICODE c = IN1;
73 DBCHAR code;
74
75 if (c < 0x80) {
76 WRITE1((unsigned char)c)
77 NEXT(1, 1)
78 continue;
79 }
80 UCS4INVALID(c)
81
82 REQUIRE_OUTBUF(2)
83 TRYMAP_ENC(cp950ext, code, c);
84 else TRYMAP_ENC(big5, code, c);
85 else return 1;
86
87 OUT1(code >> 8)
88 OUT2(code & 0xFF)
89 NEXT(1, 2)
90 }
91
92 return 0;
93}
94
95DECODER(cp950)
96{
97 while (inleft > 0) {
98 unsigned char c = IN1;
99
100 REQUIRE_OUTBUF(1)
101
102 if (c < 0x80) {
103 OUT1(c)
104 NEXT(1, 1)
105 continue;
106 }
107
108 REQUIRE_INBUF(2)
109
110 TRYMAP_DEC(cp950ext, **outbuf, c, IN2);
111 else TRYMAP_DEC(big5, **outbuf, c, IN2);
112 else return 2;
113
114 NEXT(2, 1)
115 }
116
117 return 0;
118}
119
120
121
122BEGIN_MAPPINGS_LIST
123 MAPPING_ENCDEC(big5)
124 MAPPING_ENCDEC(cp950ext)
125END_MAPPINGS_LIST
126
127BEGIN_CODECS_LIST
128 CODEC_STATELESS(big5)
129 CODEC_STATELESS(cp950)
130END_CODECS_LIST
131
132I_AM_A_MODULE_FOR(tw)
Note: See TracBrowser for help on using the repository browser.