asciinema.org/lib/asciinema/string_utils.ex
2017-07-04 11:43:10 +00:00

23 lines
479 B
Elixir

defmodule Asciinema.StringUtils do
def valid_part(invalid_str, str) do
case String.chunk(invalid_str <> str, :valid) do
[] ->
{"", ""}
chunks ->
str =
chunks
|> Enum.take(Enum.count(chunks) - 1)
|> Enum.filter(&String.valid?/1)
|> Enum.join
last = Enum.at(chunks, -1)
if String.valid?(last) do
{str <> last, ""}
else
{str, last}
end
end
end
end