diff options
Diffstat (limited to 'main.ha')
| -rw-r--r-- | main.ha | 22 |
1 files changed, 10 insertions, 12 deletions
@@ -203,7 +203,7 @@ fn parse_srt(file: io::handle) []subtitle = { let current = subtitle { ... }; let content = strio::dynamic(); defer io::close(&content)!; - fmt::fprint(&content, "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<root>\n")!; + strio::concat(&content, "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<root>\n")!; let state = state::INDEX; for (let nr = 0; true; nr += 1) { @@ -240,29 +240,27 @@ fn parse_srt(file: io::handle) []subtitle = { state = state::TEXT; case state::TEXT => if (len(line) > 0) { - fmt::fprintf(&content, "{}\n", line)!; + strio::concat(&content, line, "\n")!; continue; }; - fmt::fprint(&content, "</root>")!; - let buf = bufio::fixed( - strings::toutf8(strio::string(&content)), - io::mode::READ, - ); + strio::concat(&content, "</root>")!; + let content_str = strio::string(&content); + let buf = bufio::fixed(strings::toutf8(content_str), io::mode::READ); current.text = match (parse_text(&buf)) { case let t: []text => yield t; - case let err: io::error => - fmt::fatal("Error parsing subtitles:", io::strerror(err)); - case let err: xml::error => - fmt::fatal("Error parsing subtitles:", xml::strerror(err)); + case => + let content = strings::trimprefix(content_str, "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<root>"); + let content = strings::trimsuffix(content, "</root>"); + yield alloc([strings::replace(content, "\n", "\r\n")]); }; append(subtitles, current); current = subtitle { ... }; strio::reset(&content); - fmt::fprint(&content, "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<root>\n")!; + strio::concat(&content, "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<root>\n")!; state = state::INDEX; }; |
