Skip to content

Commit c790a71

Browse files
committed
refactor: minor code unification
1 parent 9f461d8 commit c790a71

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

fallback/multi-byte.js

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,18 @@ const mappers = {
1717
const euc = getTable('euc-kr')
1818
let lead = 0
1919

20+
const decodeLead = (b) => {
21+
const cp = b >= 0x41 && b <= 0xfe ? euc[(lead - 0x81) * 190 + b - 0x41] : undefined
22+
lead = 0
23+
if (cp !== undefined && cp !== REP) return String.fromCharCode(cp)
24+
return b < 128 ? String.fromCharCode(err(), b) : String.fromCharCode(err())
25+
}
26+
2027
const fast = (arr, start, end, stream) => {
2128
let res = ''
2229
let i = start
2330

24-
const decodeLead = (b) => {
25-
const cp = b >= 0x41 && b <= 0xfe ? euc[(lead - 0x81) * 190 + b - 0x41] : undefined
26-
lead = 0
27-
if (cp !== undefined && cp !== REP) {
28-
res += String.fromCharCode(cp)
29-
} else {
30-
res += String.fromCharCode(err())
31-
if (b < 128) res += String.fromCharCode(b)
32-
}
33-
}
34-
35-
if (lead && i < end) decodeLead(arr[i++])
31+
if (lead && i < end) res += decodeLead(arr[i++])
3632
while (i < end) {
3733
const b = arr[i++]
3834
if (b < 128) {
@@ -41,7 +37,7 @@ const mappers = {
4137
res += String.fromCharCode(err())
4238
} else {
4339
lead = b
44-
if (i < end) decodeLead(arr[i++])
40+
if (i < end) res += decodeLead(arr[i++])
4541
}
4642
}
4743

0 commit comments

Comments
 (0)