diff options
author | bptato <nincsnevem662@gmail.com> | 2023-05-16 13:17:41 +0200 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2023-05-16 13:18:47 +0200 |
commit | 4e0fd8c7ef2ad2f61c1ac0572e02b92b1c42b688 (patch) | |
tree | 83adafc3a2046bb8af09d7c57340dc9374eebbd6 /src/encoding | |
parent | 951d587f7edf3544d30ba039530a1d19b7e9db78 (diff) | |
download | chawan-4e0fd8c7ef2ad2f61c1ac0572e02b92b1c42b688.tar.gz |
Refactor config, add charset opts
Only document-charset supported for now.
Diffstat (limited to 'src/encoding')
-rw-r--r-- | src/encoding/decoderstream.nim | 34 |
1 files changed, 17 insertions, 17 deletions
diff --git a/src/encoding/decoderstream.nim b/src/encoding/decoderstream.nim index 362d9607..425f264f 100644 --- a/src/encoding/decoderstream.nim +++ b/src/encoding/decoderstream.nim @@ -505,26 +505,26 @@ proc decodeShiftJIS(stream: DecoderStream, iq: var seq[uint8], while i < ilen: let b = iq[i] if lead != 0: - let l = lead - lead = 0 + var ptrisnull = true; + var p = 0u16 let offset = if b < 0x7Fu8: 0x40u16 else: 0x41u16 - let leadoffset = if l < 0xA0: 0x81u16 else: 0xC1u16 + let leadoffset = if lead < 0xA0: 0x81u16 else: 0xC1u16 if b in 0x40u8..0x7Eu8 or b in 0x80u8..0xFCu8: - let p = (uint16(l) - leadoffset) * 188 + uint16(b) - offset - if p in 8836u16..10715u16: - stream.append_codepoint 0xE000u16 - 8836 + p, oq, olen, n - inc i - continue - if p < Jis0208Decode.len and Jis0208Decode[p] != 0: - let c = Jis0208Decode[p] - stream.append_codepoint c, oq, olen, n - inc i - continue - if cast[char](b) in Ascii: - continue # prepend (no inc i) + p = (uint16(lead) - leadoffset) * 188 + uint16(b) - offset + ptrisnull = false + lead = 0 + if not ptrisnull and p in 8836u16..10715u16: + stream.append_codepoint 0xE000u16 - 8836 + p, oq, olen, n + inc i + continue + elif not ptrisnull and p < Jis0208Decode.len and Jis0208Decode[p] != 0: + let c = Jis0208Decode[p] + stream.append_codepoint c, oq, olen, n else: stream.handleError(oq, olen, n) if stream.isend: break + if cast[char](b) in Ascii: + continue # prepend (no inc i) elif cast[char](b) in Ascii or b == 0x80: stream.append_codepoint b, oq, olen, n elif b in 0xA1u8..0xDFu8: @@ -640,11 +640,11 @@ proc decodeSingleByte(stream: DecoderStream, iq: var seq[uint8], if c in Ascii: stream.append_codepoint c, oq, olen, n else: - let p = map[c] + let p = map[cast[char](iq[i] - 0x80)] if p == 0u16: stream.handleError(oq, olen, n) else: - stream.append_codepoint cast[uint32](oq), oq, olen, n + stream.append_codepoint cast[uint32](p), oq, olen, n proc decodeReplacement(stream: DecoderStream, oq: ptr UncheckedArray[uint32], olen: int, n: var int) = if not stream.replreported: |