Skip to content

Commit

Permalink
better whitespace handling
Browse files Browse the repository at this point in the history
  • Loading branch information
bismark committed Mar 21, 2023
1 parent d174f94 commit 5270840
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
3 changes: 2 additions & 1 deletion lib/vttyl/decode.ex
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,10 @@ defmodule Vttyl.Decode do
Regex.match?(@line_regex, line)
end

@annotation_space_regex ~r/[ \t]/
defp parse_text("<v" <> line) do
[voice, text] = String.split(line, ">", parts: 2)
voice = String.split(voice, " ") |> List.last()
[_, voice] = String.split(voice, @annotation_space_regex, parts: 2)
{voice, text}
end

Expand Down
4 changes: 2 additions & 2 deletions priv/samples/voice.vtt
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ WEBVTT

2
00:02.000 --> 00:04.000
<v Mary>No way!
<v Mary>No way!

3
00:04.000 --> 00:06.000
<v Esme>Hee!
<v Esme F>Hee!

4
00:06.000 --> 00:08.000
Expand Down
2 changes: 1 addition & 1 deletion test/vttyl_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ defmodule VttylTest do
|> Stream.map(& &1.voice)
|> Enum.into([])

assert ["Esme", "Mary", "Esme", "Mary"] == parsed
assert ["Esme", "Mary", "Esme F", "Mary"] == parsed
end
end

Expand Down

0 comments on commit 5270840

Please sign in to comment.