summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--main.ha21
1 files changed, 12 insertions, 9 deletions
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("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<root>\n"))!;
+ fmt::fprint(&content, "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<root>\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("</root>"))!;
- content.pos = 0;
- current.text = match (parse_text(&content)) {
+ fmt::fprint(&content, "</root>")!;
+ 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("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<root>\n"))!;
+ strio::reset(&content);
+ fmt::fprint(&content, "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<root>\n")!;
state = state::INDEX;
};