hautils

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 9a9e44aaf1947567ba1461c5e9430c864d979a43
parent b67c9fa5decb33dc2f2b07a43f191d3b66264c99
Author: Byron Torres <b@torresjrjr.com>
Date:   Thu, 28 Apr 2022 23:00:11 +0100

nl: use strings::try_fromutf8

Diffstat:
Mnl.ha | 9++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/nl.ha b/nl.ha @@ -1,5 +1,6 @@ use ascii; use bufio; +use encoding::utf8; use fmt; use fs; use getopt; @@ -203,7 +204,13 @@ export fn utilmain() (void | main::error) = { yield rawline; }; defer free(rawline); - const line = fmt::bsprint(rawline); + + const line = match (strings::try_fromutf8(rawline)) { + case let line: str => + yield line; + case encoding::utf8::invalid => + fmt::fatal("Error: Invalid UTF-8 input"); + }; if (line == delim_head) { section = section::HEAD;