From 527084055b80f67eea6e27443bd0545bcbfa6042 Mon Sep 17 00:00:00 2001 From: Ryan Johnson Date: Tue, 21 Mar 2023 16:55:36 -0600 Subject: [PATCH] better whitespace handling --- lib/vttyl/decode.ex | 3 ++- priv/samples/voice.vtt | 4 ++-- test/vttyl_test.exs | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/vttyl/decode.ex b/lib/vttyl/decode.ex index 3e39fcc..2885cfc 100644 --- a/lib/vttyl/decode.ex +++ b/lib/vttyl/decode.ex @@ -60,9 +60,10 @@ defmodule Vttyl.Decode do Regex.match?(@line_regex, line) end + @annotation_space_regex ~r/[ \t]/ defp parse_text(" 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 diff --git a/priv/samples/voice.vtt b/priv/samples/voice.vtt index da471c4..03d5a27 100644 --- a/priv/samples/voice.vtt +++ b/priv/samples/voice.vtt @@ -6,11 +6,11 @@ WEBVTT 2 00:02.000 --> 00:04.000 -No way! +No way! 3 00:04.000 --> 00:06.000 -Hee! +Hee! 4 00:06.000 --> 00:08.000 diff --git a/test/vttyl_test.exs b/test/vttyl_test.exs index f9b76d2..a1540ec 100644 --- a/test/vttyl_test.exs +++ b/test/vttyl_test.exs @@ -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