Updated documentation for findCaller() to indicate that a 3-tuple is now returned...
[python.git] / Modules / cjkcodecs / _codecs_hk.c
blob221eced3cc659b4a26ccdf0996cccefb8f804d72
1 /*
2 * _codecs_hk.c: Codecs collection for encodings from Hong Kong
4 * Written by Hye-Shik Chang <perky@FreeBSD.org>
5 */
7 #define USING_IMPORTED_MAPS
9 #include "cjkcodecs.h"
10 #include "mappings_hk.h"
13 * BIG5HKSCS codec
16 static const encode_map *big5_encmap = NULL;
17 static const decode_map *big5_decmap = NULL;
19 CODEC_INIT(big5hkscs)
21 static int initialized = 0;
23 if (!initialized && IMPORT_MAP(tw, big5, &big5_encmap, &big5_decmap))
24 return -1;
25 initialized = 1;
26 return 0;
29 ENCODER(big5hkscs)
31 while (inleft > 0) {
32 ucs4_t c = **inbuf;
33 DBCHAR code;
34 Py_ssize_t insize;
36 if (c < 0x80) {
37 REQUIRE_OUTBUF(1)
38 **outbuf = (unsigned char)c;
39 NEXT(1, 1)
40 continue;
43 DECODE_SURROGATE(c)
44 insize = GET_INSIZE(c);
46 REQUIRE_OUTBUF(2)
48 if (c < 0x10000) {
49 TRYMAP_ENC(big5hkscs_bmp, code, c);
50 else TRYMAP_ENC(big5, code, c);
51 else return 1;
53 else if (c < 0x20000)
54 return insize;
55 else if (c < 0x30000) {
56 TRYMAP_ENC(big5hkscs_nonbmp, code, c & 0xffff);
57 else return insize;
59 else
60 return insize;
62 OUT1(code >> 8)
63 OUT2(code & 0xFF)
64 NEXT(insize, 2)
67 return 0;
70 #define BH2S(c1, c2) (((c1) - 0x88) * (0xfe - 0x40 + 1) + ((c2) - 0x40))
72 DECODER(big5hkscs)
74 while (inleft > 0) {
75 unsigned char c = IN1;
76 ucs4_t decoded;
78 REQUIRE_OUTBUF(1)
80 if (c < 0x80) {
81 OUT1(c)
82 NEXT(1, 1)
83 continue;
86 REQUIRE_INBUF(2)
88 if (0xc6 <= c && c <= 0xc8 && (c >= 0xc7 || IN2 >= 0xa1))
89 goto hkscsdec;
91 TRYMAP_DEC(big5, **outbuf, c, IN2) {
92 NEXT(2, 1)
94 else
95 hkscsdec: TRYMAP_DEC(big5hkscs, decoded, c, IN2) {
96 int s = BH2S(c, IN2);
97 const unsigned char *hintbase;
99 assert(0x88 <= c && c <= 0xfe);
100 assert(0x40 <= IN2 && IN2 <= 0xfe);
102 if (BH2S(0x88, 0x40) <= s && s <= BH2S(0xa0, 0xfe)) {
103 hintbase = big5hkscs_phint_0;
104 s -= BH2S(0x88, 0x40);
106 else if (BH2S(0xc6,0xa1) <= s && s <= BH2S(0xc8,0xfe)){
107 hintbase = big5hkscs_phint_11939;
108 s -= BH2S(0xc6, 0xa1);
110 else if (BH2S(0xf9,0xd6) <= s && s <= BH2S(0xfe,0xfe)){
111 hintbase = big5hkscs_phint_21733;
112 s -= BH2S(0xf9, 0xd6);
114 else
115 return MBERR_INTERNAL;
117 if (hintbase[s >> 3] & (1 << (s & 7))) {
118 WRITEUCS4(decoded | 0x20000)
119 NEXT_IN(2)
121 else {
122 OUT1(decoded)
123 NEXT(2, 1)
126 else return 2;
129 return 0;
133 BEGIN_MAPPINGS_LIST
134 MAPPING_DECONLY(big5hkscs)
135 MAPPING_ENCONLY(big5hkscs_bmp)
136 MAPPING_ENCONLY(big5hkscs_nonbmp)
137 END_MAPPINGS_LIST
139 BEGIN_CODECS_LIST
140 CODEC_STATELESS_WINIT(big5hkscs)
141 END_CODECS_LIST
143 I_AM_A_MODULE_FOR(hk)