diff options
author | bptato <nincsnevem662@gmail.com> | 2022-12-18 20:46:30 +0100 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2022-12-18 20:46:30 +0100 |
commit | bfaf210d87e90016f8f2521657bd04686170aa43 (patch) | |
tree | e9711cb2f72174058d88ce2d52a76239e3c54c62 /src/encoding | |
parent | 1fbe17eeddefb87bf8e819be7792ae7a6482d8f8 (diff) | |
download | chawan-bfaf210d87e90016f8f2521657bd04686170aa43.tar.gz |
Add JS support to documents
Diffstat (limited to 'src/encoding')
-rw-r--r-- | src/encoding/decoderstream.nim | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/encoding/decoderstream.nim b/src/encoding/decoderstream.nim index 15d6311c..e3161921 100644 --- a/src/encoding/decoderstream.nim +++ b/src/encoding/decoderstream.nim @@ -826,6 +826,16 @@ proc readRunes*(stream: DecoderStream, olen: int): seq[Rune] = proc atEnd*(stream: DecoderStream): bool = return stream.isend +# Read all and convert to UTF-8. +# Probably not very efficient. Oh well. +proc readAll*(stream: DecoderStream): string = + var buf = newSeqUninitialized[uint32](stream.buflen) + while not stream.atEnd: + let n = stream.readData(addr buf, buf.len * sizeof(buf[0])) + for i in 0 ..< n div 4: + let r = cast[Rune](buf[i]) + result &= $r + proc newDecoderStream*(source: Stream, cs = CHARSET_UTF_8, buflen = 1024, errormode = DECODER_ERROR_MODE_REPLACEMENT): DecoderStream = result = DecoderStream( |