diff options
Diffstat (limited to 'main.ha')
| -rw-r--r-- | main.ha | 38 |
1 files changed, 20 insertions, 18 deletions
@@ -202,12 +202,14 @@ type state = enum { TEXT, }; +def XML_PROLOG: str = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<root>\n"; + fn parse_srt(file: io::handle) []subtitle = { let subtitles: []subtitle = []; let current = subtitle { ... }; let content = strio::dynamic(); defer io::close(&content)!; - strio::concat(&content, "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<root>\n")!; + strio::concat(&content, XML_PROLOG)!; let state = state::INDEX; for (let nr = 0; true; nr += 1) { @@ -255,7 +257,7 @@ fn parse_srt(file: io::handle) []subtitle = { case let t: []text => yield t; case => - let content = strings::trimprefix(content_str, "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<root>"); + let content = strings::trimprefix(content_str, XML_PROLOG); let content = strings::trimsuffix(content, "</root>"); yield alloc([strings::replace(content, "\n", "\r\n")]); }; @@ -264,7 +266,7 @@ fn parse_srt(file: io::handle) []subtitle = { current = subtitle { ... }; strio::reset(&content); - strio::concat(&content, "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<root>\n")!; + strio::concat(&content, XML_PROLOG)!; state = state::INDEX; }; @@ -299,9 +301,9 @@ fn parse_text(in: io::handle) ([]text | io::error | xml::error) = { defer xml::parser_free(parser); let text: []text = []; - let bold = false; - let italic = false; - let underline = false; + let bold = 0; + let italic = 0; + let underline = 0; for (true) { let tok = match (xml::scan(parser)?) { case let tok: xml::token => @@ -314,39 +316,39 @@ fn parse_text(in: io::handle) ([]text | io::error | xml::error) = { case let start: xml::elementstart => switch (start) { case "b" => - if (!bold) { + if (bold == 0) { append(text, true: setbold); - bold = true; }; + bold += 1; case "i" => - if (!italic) { + if (italic == 0) { append(text, true: setitalic); - italic = true; }; + italic += 1; case "u" => - if (!underline) { + if (underline == 0) { append(text, true: setunderline); - underline = true; }; + underline += 1; case => void; }; case let end: xml::elementend => switch (end) { case "b" => - if (bold) { + if (bold == 1) { append(text, false: setbold); - bold = false; }; + bold -= 1; case "i" => - if (italic) { + if (italic == 1) { append(text, false: setitalic); - italic = false; }; + italic -= 1; case "u" => - if (underline) { + if (underline == 1) { append(text, false: setunderline); - underline = false; }; + underline -= 1; case => void; }; case xml::attribute => void; |
