Whitespace normalization.
[python/dscho.git] / Modules / cjkcodecs / _gb2312.c
blob765986098701c62d19b8ddaed7d3d1c85c6b2ee9
1 /*
2 * _gb2312.c: the GB2312 codec
4 * Written by Hye-Shik Chang <perky@FreeBSD.org>
5 * $CJKCodecs: _gb2312.c,v 1.2 2003/12/31 05:46:55 perky Exp $
6 */
8 #include "codeccommon.h"
10 ENCMAP(gbcommon)
11 DECMAP(gb2312)
13 ENCODER(gb2312)
15 while (inleft > 0) {
16 Py_UNICODE c = IN1;
17 DBCHAR code;
19 if (c < 0x80) {
20 WRITE1((unsigned char)c)
21 NEXT(1, 1)
22 continue;
24 UCS4INVALID(c)
26 RESERVE_OUTBUF(2)
27 TRYMAP_ENC(gbcommon, code, c);
28 else return 1;
30 if (code & 0x8000) /* MSB set: GBK */
31 return 1;
33 OUT1((code >> 8) | 0x80)
34 OUT2((code & 0xFF) | 0x80)
35 NEXT(1, 2)
38 return 0;
41 DECODER(gb2312)
43 while (inleft > 0) {
44 unsigned char c = **inbuf;
46 RESERVE_OUTBUF(1)
48 if (c < 0x80) {
49 OUT1(c)
50 NEXT(1, 1)
51 continue;
54 RESERVE_INBUF(2)
55 TRYMAP_DEC(gb2312, **outbuf, c ^ 0x80, IN2 ^ 0x80) {
56 NEXT(2, 1)
57 } else return 2;
60 return 0;
63 #include "codecentry.h"
64 BEGIN_CODEC_REGISTRY(gb2312)
65 MAPOPEN(zh_CN)
66 IMPORTMAP_DEC(gb2312)
67 IMPORTMAP_ENC(gbcommon)
68 MAPCLOSE()
69 END_CODEC_REGISTRY(gb2312)