mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-27 13:47:58 +01:00
31 lines
597 B
Elixir
31 lines
597 B
Elixir
defmodule PhilomenaQuery.Parse.String do
|
|
@moduledoc """
|
|
Search string normalization utilities.
|
|
"""
|
|
|
|
@doc """
|
|
Convert a multiline or empty search string into a single search string.
|
|
|
|
## Examples
|
|
|
|
iex> Search.String.normalize(nil)
|
|
""
|
|
|
|
iex> Search.String.normalize("foo\nbar")
|
|
"(foo) || (bar)"
|
|
|
|
"""
|
|
@spec normalize(String.t() | nil) :: String.t()
|
|
def normalize(str)
|
|
|
|
def normalize(nil) do
|
|
""
|
|
end
|
|
|
|
def normalize(str) do
|
|
str
|
|
|> String.replace("\r", "")
|
|
|> String.split("\n", trim: true)
|
|
|> Enum.map_join(" || ", &"(#{&1})")
|
|
end
|
|
end
|