From aaf9675d7d73f334f6cb6305066451db7a32e12e Mon Sep 17 00:00:00 2001 From: Sam Nystrom Date: Fri, 23 Jun 2023 17:04:12 -0400 Subject: Don't rely on implementation details of bufio Previously we modified internal fields of bufio::memstream to make it readable, which is bad. This commit uses bufio::fixed to read from a strio::stream. --- main.ha | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'main.ha') diff --git a/main.ha b/main.ha index 42e7039..f66c67f 100644 --- a/main.ha +++ b/main.ha @@ -24,6 +24,7 @@ use fs; use os; use strconv; use strings; +use strio; use time; use unix::poll; use unix::tty; @@ -200,9 +201,9 @@ type state = enum { fn parse_srt(file: io::handle) []subtitle = { let subtitles: []subtitle = []; let current = subtitle { ... }; - let content = bufio::dynamic(io::mode::RDWR); + let content = strio::dynamic(); defer io::close(&content)!; - io::writeall(&content, strings::toutf8("\n\n"))!; + fmt::fprint(&content, "\n\n")!; let state = state::INDEX; for (let nr = 0; true; nr += 1) { @@ -239,14 +240,16 @@ fn parse_srt(file: io::handle) []subtitle = { state = state::TEXT; case state::TEXT => if (len(line) > 0) { - io::writeall(&content, strings::toutf8(line))!; - io::writeall(&content, strings::toutf8("\n"))!; + fmt::fprintf(&content, "{}\n", line)!; continue; }; - io::writeall(&content, strings::toutf8(""))!; - content.pos = 0; - current.text = match (parse_text(&content)) { + fmt::fprint(&content, "")!; + let buf = bufio::fixed( + strings::toutf8(strio::string(&content)), + io::mode::READ, + ); + current.text = match (parse_text(&buf)) { case let t: []text => yield t; case let err: io::error => @@ -258,8 +261,8 @@ fn parse_srt(file: io::handle) []subtitle = { append(subtitles, current); current = subtitle { ... }; - bufio::reset(&content); - io::writeall(&content, strings::toutf8("\n\n"))!; + strio::reset(&content); + fmt::fprint(&content, "\n\n")!; state = state::INDEX; }; -- cgit v1.2.3