commit f180fef42c0bf8ffbbd8caa5416436abb6c68500
parent 7d02a6218329bd0cd0e40a4a8246b8d5cddff205
Author: Sebastian <sebastian@sebsite.pw>
Date: Thu, 23 Jun 2022 19:23:59 -0400
bufio: return utf8::invalid in more cases
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>
Diffstat:
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/bufio/scanner.ha b/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;
};
};