diff options
author | Hye-Shik Chang <hyeshik@gmail.com> | 2004-01-17 14:29:29 (GMT) |
---|---|---|
committer | Hye-Shik Chang <hyeshik@gmail.com> | 2004-01-17 14:29:29 (GMT) |
commit | 3e2a30692085d32ac63f72b35da39158a471fc68 (patch) | |
tree | 4cbe735f61eae87ac56a13ca6bd32113b98bd03d /Modules/cjkcodecs/_cp950.c | |
parent | cd1f7430cb8f48de970021071d7683054c23b10f (diff) | |
download | cpython-3e2a30692085d32ac63f72b35da39158a471fc68.zip cpython-3e2a30692085d32ac63f72b35da39158a471fc68.tar.gz cpython-3e2a30692085d32ac63f72b35da39158a471fc68.tar.bz2 |
Add CJK codecs support as discussed on python-dev. (SF #873597)
Several style fixes are suggested by Martin v. Loewis and
Marc-Andre Lemburg. Thanks!
Diffstat (limited to 'Modules/cjkcodecs/_cp950.c')
-rw-r--r-- | Modules/cjkcodecs/_cp950.c | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/Modules/cjkcodecs/_cp950.c b/Modules/cjkcodecs/_cp950.c new file mode 100644 index 0000000..b0644f0 --- /dev/null +++ b/Modules/cjkcodecs/_cp950.c @@ -0,0 +1,72 @@ +/* + * _cp950.c: the CP950 codec + * + * Written by Hye-Shik Chang <perky@FreeBSD.org> + * $CJKCodecs: _cp950.c,v 1.2 2003/12/31 05:46:55 perky Exp $ + */ + +#include "codeccommon.h" + +ENCMAP(big5) +ENCMAP(cp950ext) +DECMAP(big5) +DECMAP(cp950ext) + +ENCODER(cp950) +{ + while (inleft > 0) { + Py_UNICODE c = IN1; + DBCHAR code; + + if (c < 0x80) { + WRITE1(c) + NEXT(1, 1) + continue; + } + UCS4INVALID(c) + + RESERVE_OUTBUF(2) + TRYMAP_ENC(cp950ext, code, c); + else TRYMAP_ENC(big5, code, c); + else return 1; + + OUT1(code >> 8) + OUT2(code & 0xFF) + NEXT(1, 2) + } + + return 0; +} + +DECODER(cp950) +{ + while (inleft > 0) { + unsigned char c = IN1; + + RESERVE_OUTBUF(1) + + if (c < 0x80) { + OUT1(c) + NEXT(1, 1) + continue; + } + + RESERVE_INBUF(2) + + TRYMAP_DEC(cp950ext, **outbuf, c, IN2); + else TRYMAP_DEC(big5, **outbuf, c, IN2); + else return 2; + + NEXT(2, 1) + } + + return 0; +} + +#include "codecentry.h" +BEGIN_CODEC_REGISTRY(cp950) + MAPOPEN(zh_TW) + IMPORTMAP_ENCDEC(big5) + IMPORTMAP_ENCDEC(cp950ext) + MAPCLOSE() +END_CODEC_REGISTRY(cp950) |