about summary refs log tree commit diff stats
path: root/src/encoding
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2023-07-06 13:53:27 +0200
committerbptato <nincsnevem662@gmail.com>2023-07-06 13:53:27 +0200
commitf919cd6c39804f8f5c03a3b6125de8bf55fa4d38 (patch)
tree0d9e89136e280d882d62260b8a27ae866c717a2c /src/encoding
parentfbeed195b9f0f7df8a0cf7149c815efa5089f13c (diff)
downloadchawan-f919cd6c39804f8f5c03a3b6125de8bf55fa4d38.tar.gz
decoderstream: fix incorrect Big5 decoding
Diffstat (limited to 'src/encoding')
-rw-r--r--src/encoding/decoderstream.nim8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/encoding/decoderstream.nim b/src/encoding/decoderstream.nim
index 62e69f7f..51feb85d 100644
--- a/src/encoding/decoderstream.nim
+++ b/src/encoding/decoderstream.nim
@@ -273,8 +273,8 @@ proc decodeBig5(stream: DecoderStream, iq: var seq[uint8],
     if stream.big5lead != 0:
       let lead = uint32(stream.big5lead)
       stream.big5lead = 0
-      let offset = if iq[i] < 0x7F: 0x40u16 else: 0x7E
-      if iq[i] in {0x40u8 .. 0x7Eu8, 0xA1 .. 0xFEu8}:
+      let offset = if iq[i] < 0x7F: 0x40u16 else: 0x62u16
+      if iq[i] in {0x40u8 .. 0x7Eu8, 0xA1u8 .. 0xFEu8}:
         let p = (lead - 0x81) * 157 + uint16(iq[i]) - offset
         template output_two(a, b: uint32) =
           stream.append_codepoint a, oq, olen, n
@@ -288,7 +288,7 @@ proc decodeBig5(stream: DecoderStream, iq: var seq[uint8],
           else: break no_continue
           inc i
           continue
-        if p < Big5Decode.len - Big5DecodeOffset:
+        if p < Big5Decode.len + Big5DecodeOffset:
           let c = Big5Decode[p - Big5DecodeOffset]
           if c != 0:
             stream.append_codepoint c, oq, olen, n
@@ -301,7 +301,7 @@ proc decodeBig5(stream: DecoderStream, iq: var seq[uint8],
         if stream.isend: break
     elif cast[char](iq[i]) in Ascii:
       stream.append_codepoint iq[i], oq, olen, n
-    elif iq[i] in 0x00u8 .. 0xFEu8:
+    elif iq[i] in 0x81u8 .. 0xFEu8:
       stream.big5lead = iq[i]
     else:
       stream.handleError(oq, olen, n)