Both io::underread and utf8::more result in the function returning
utf8::invalid, since these are only possible if the codepoint is
malformed.
Signed-off-by: Sebastian <sebastian@sebsite.pw>
---
bufio/scanner.ha | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/bufio/scanner.ha b/bufio/scanner.ha
index 3e24cb87..b900698d 100644
--- a/bufio/scanner.ha
@@ -74,18 +74,22 @@ export fn scanrune(
return b[0]: u32: rune;
};
- match (io::readall(file, b[1..sz])?) {
+ match (io::readall(file, b[1..sz])) {
case let n: size => void;
case io::EOF =>
return io::EOF;
+ case let err: io::error =>
+ return if (err is io::underread) utf8::invalid else err;
};
let dec = utf8::decode(b[..sz]);
match (utf8::next(&dec)?) {
case let r: rune =>
return r;
- case (void | utf8::more) =>
+ case void =>
return io::EOF;
+ case utf8::more =>
+ return utf8::invalid;
};
};
--
2.36.1