Skip to content

Commit 5dfe3bb

Browse files
author
Victor Stinner
committed
Issue python#12016: Reindent decoders of HK and JP codecs
1 parent 98e68ad commit 5dfe3bb

File tree

2 files changed

+52
-51
lines changed

2 files changed

+52
-51
lines changed

Modules/cjkcodecs/_codecs_hk.c

Lines changed: 47 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -115,55 +115,56 @@ DECODER(big5hkscs)
115115

116116
REQUIRE_INBUF(2)
117117

118-
if (0xc6 <= c && c <= 0xc8 && (c >= 0xc7 || IN2 >= 0xa1))
119-
goto hkscsdec;
118+
if (0xc6 > c || c > 0xc8 || (c < 0xc7 && IN2 < 0xa1)) {
119+
TRYMAP_DEC(big5, **outbuf, c, IN2) {
120+
NEXT(2, 1)
121+
continue;
122+
}
123+
}
124+
125+
TRYMAP_DEC(big5hkscs, decoded, c, IN2)
126+
{
127+
int s = BH2S(c, IN2);
128+
const unsigned char *hintbase;
129+
130+
assert(0x87 <= c && c <= 0xfe);
131+
assert(0x40 <= IN2 && IN2 <= 0xfe);
132+
133+
if (BH2S(0x87, 0x40) <= s && s <= BH2S(0xa0, 0xfe)) {
134+
hintbase = big5hkscs_phint_0;
135+
s -= BH2S(0x87, 0x40);
136+
}
137+
else if (BH2S(0xc6,0xa1) <= s && s <= BH2S(0xc8,0xfe)){
138+
hintbase = big5hkscs_phint_12130;
139+
s -= BH2S(0xc6, 0xa1);
140+
}
141+
else if (BH2S(0xf9,0xd6) <= s && s <= BH2S(0xfe,0xfe)){
142+
hintbase = big5hkscs_phint_21924;
143+
s -= BH2S(0xf9, 0xd6);
144+
}
145+
else
146+
return MBERR_INTERNAL;
120147

121-
TRYMAP_DEC(big5, **outbuf, c, IN2) {
122-
NEXT(2, 1)
148+
if (hintbase[s >> 3] & (1 << (s & 7))) {
149+
WRITEUCS4(decoded | 0x20000)
150+
NEXT_IN(2)
151+
}
152+
else {
153+
OUT1(decoded)
154+
NEXT(2, 1)
155+
}
156+
continue;
123157
}
124-
else
125-
hkscsdec: TRYMAP_DEC(big5hkscs, decoded, c, IN2) {
126-
int s = BH2S(c, IN2);
127-
const unsigned char *hintbase;
128-
129-
assert(0x87 <= c && c <= 0xfe);
130-
assert(0x40 <= IN2 && IN2 <= 0xfe);
131-
132-
if (BH2S(0x87, 0x40) <= s && s <= BH2S(0xa0, 0xfe)) {
133-
hintbase = big5hkscs_phint_0;
134-
s -= BH2S(0x87, 0x40);
135-
}
136-
else if (BH2S(0xc6,0xa1) <= s && s <= BH2S(0xc8,0xfe)){
137-
hintbase = big5hkscs_phint_12130;
138-
s -= BH2S(0xc6, 0xa1);
139-
}
140-
else if (BH2S(0xf9,0xd6) <= s && s <= BH2S(0xfe,0xfe)){
141-
hintbase = big5hkscs_phint_21924;
142-
s -= BH2S(0xf9, 0xd6);
143-
}
144-
else
145-
return MBERR_INTERNAL;
146-
147-
if (hintbase[s >> 3] & (1 << (s & 7))) {
148-
WRITEUCS4(decoded | 0x20000)
149-
NEXT_IN(2)
150-
}
151-
else {
152-
OUT1(decoded)
153-
NEXT(2, 1)
154-
}
155-
}
156-
else {
157-
switch ((c << 8) | IN2) {
158-
case 0x8862: WRITE2(0x00ca, 0x0304); break;
159-
case 0x8864: WRITE2(0x00ca, 0x030c); break;
160-
case 0x88a3: WRITE2(0x00ea, 0x0304); break;
161-
case 0x88a5: WRITE2(0x00ea, 0x030c); break;
162-
default: return 2;
163-
}
164-
165-
NEXT(2, 2) /* all decoded codepoints are pairs, above. */
158+
159+
switch ((c << 8) | IN2) {
160+
case 0x8862: WRITE2(0x00ca, 0x0304); break;
161+
case 0x8864: WRITE2(0x00ca, 0x030c); break;
162+
case 0x88a3: WRITE2(0x00ea, 0x0304); break;
163+
case 0x88a5: WRITE2(0x00ea, 0x030c); break;
164+
default: return 2;
166165
}
166+
167+
NEXT(2, 2) /* all decoded codepoints are pairs, above. */
167168
}
168169

169170
return 0;

Modules/cjkcodecs/_codecs_jp.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -371,11 +371,11 @@ DECODER(euc_jp)
371371

372372
REQUIRE_OUTBUF(1)
373373

374-
if (c < 0x80) {
375-
OUT1(c)
376-
NEXT(1, 1)
377-
continue;
378-
}
374+
if (c < 0x80) {
375+
OUT1(c)
376+
NEXT(1, 1)
377+
continue;
378+
}
379379

380380
if (c == 0x8e) {
381381
/* JIS X 0201 half-width katakana */

0 commit comments

Comments
 (0)