ExAequoBase.Text (ExAequoBase v0.1.6)
View SourceText based tools
Summary
Functions
Removes a prefix (only if matching), or a given count of graphemes from the front of a string
Parses an input string up to a given string, returnig prefix and suffix
Types
@type atoms() :: [atom()]
@type binaries() :: [binary()]
@type error_t() :: {:error, binary()}
@type error_t(t) :: {:error, t}
@type maybe(t) :: nil | t
@type natural() :: non_neg_integer()
@type numbered(t) :: {t, number()}
@type numbered_lines_t() :: [numbered_line_t()]
@type ok_t() :: {:ok, any()}
@type ok_t(t) :: {:ok, t}
@type pair_t(t) :: {t, t}
@type pair_t(lt, rt) :: {lt, rt}
@type pairs_t() :: [pair_t()]
@type pairs_t(t) :: [pair_t(t)]
@type pairs_t(lt, rt) :: [pair_t(lt, rt)]
@type rgx_pair() :: {Regex.t(), ExAequoFn.NamedFn.t()}
@type rgx_pairs() :: [rgx_pair()]
@type zero_fn_t() :: (-> any())
@type zero_fn_t(t) :: (-> t)
Functions
Removes a prefix (only if matching), or a given count of graphemes from the front of a string
iex(1)> behead("abc", "a")
"bc"
iex(2)> behead("abc", 2)
"c"
iex(3)> behead("abc", 0)
"abc"
But
iex(4)> assert_raise(
...(4)> ExAequoBase.Text.Error,
...(4)> fn -> behead("abc", "b")
...(4)> end)
iex(5)> assert_raise(
...(5)> FunctionClauseError,
...(5)> fn -> behead("abc", -1)
...(5)> end)
Parses an input string up to a given string, returnig prefix and suffix
iex(6)> parse_up_to("hello world", " ")
{"hello", "world"}
We can also use regular expressions
iex(7)> parse_up_to("hello world", ~r/\s+/)
{"hello", "world"}
We can decide to keep the string we parse up to
iex(8)> parse_up_to("hello world", ~r/\s+/, :keep)
{"hello", " world"}
Or to include it into the macth
iex(9)> parse_up_to("hello world", ~r/\s+/, :include)
{"hello ", "world"}
If no match nil is returned
iex(10)> parse_up_to("hi there", ~r/\d+/)
nil