diff options
author | bptato <nincsnevem662@gmail.com> | 2024-02-22 20:14:08 +0100 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2024-02-22 20:14:19 +0100 |
commit | 78ffc938fa7e4baad0a55625026b765d215be1aa (patch) | |
tree | 857db2e963efb13933d1e7954e9d4dc657b6f11d /src/display/lineedit.nim | |
parent | def15ede4fbd686b0ee9b193f41b2a47190aa43a (diff) | |
download | chawan-78ffc938fa7e4baad0a55625026b765d215be1aa.tar.gz |
Replace Chakasu with Chagashi
The API is horrid :( but at least it copies less. TODO: think of a better API.
Diffstat (limited to 'src/display/lineedit.nim')
-rw-r--r-- | src/display/lineedit.nim | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/src/display/lineedit.nim b/src/display/lineedit.nim index 7a5067eb..6969171e 100644 --- a/src/display/lineedit.nim +++ b/src/display/lineedit.nim @@ -1,4 +1,3 @@ -import std/streams import std/strutils import std/unicode @@ -10,9 +9,9 @@ import types/opt import utils/strwidth import utils/twtstr -import chakasu/charset -import chakasu/decoderstream -import chakasu/encoderstream +import chagashi/charset +import chagashi/validator +import chagashi/decoder type LineEditState* = enum @@ -155,15 +154,14 @@ proc backspace(edit: LineEdit) {.jsfunc.} = proc write*(edit: LineEdit, s: string, cs: Charset): bool = if cs == CHARSET_UTF_8: - if s.validateUtf8() != -1: + if s.validateUTF8Surr() != -1: return false edit.insertCharseq(s) else: - let ss = newStringStream(s) - let ds = newDecoderStream(ss, cs, errormode = DECODER_ERROR_MODE_FATAL) - let es = newEncoderStream(ds, CHARSET_UTF_8) - let s = es.readAll() - if ds.failed or es.failed: + let td = newTextDecoder(cs) + var success = false + let s = td.decodeAll(s, success) + if not success: return false edit.insertCharseq(s) return true |