Functions to introspect the Unicode word break property for binaries (Strings) and codepoints.
The primary API is word_break/1 which returns the word break property for a codepoint or the list of word break properties for a string.
The functions fetch/1, get/1 and count/1 provide introspection of the codepoint ranges associated with a given word break property. word_breaks/0, known_word_breaks/0 and aliases/0 return the underlying property data.
Summary
Functions
Returns a map of aliases for Unicode word breaks.
Returns the count of the number of characters for a given word break.
Returns the Unicode codepoint ranges for a given word break.
Returns the Unicode codepoint ranges for a given word break.
Returns a list of known Unicode word break names.
Returns the word break name(s) for the given binary or codepoint.
Returns the map of Unicode word breaks.
Functions
Returns a map of aliases for Unicode word breaks.
An alias is an alternative name for referring to a word break. Aliases are resolved by the fetch/1 and get/1 functions.
Returns
- A map with the alias as a string key and the word break name as an atom value.
Examples
iex> Unicode.WordBreak.aliases() |> Map.get("le")
:aletter
Returns the count of the number of characters for a given word break.
Arguments
word_breakis any word break name as an atom, or a string alias for a word break.
Returns
The number of codepoints that have the given word break.
:errorif the word break name is not known.
Examples
iex> Unicode.WordBreak.count(:aletter)
33973
Returns the Unicode codepoint ranges for a given word break.
Aliases are resolved by this function.
Arguments
word_breakis any word break name as an atom, or a string alias for a word break.
Returns
{:ok, range_list}whererange_listis a list of codepoint ranges as 2-tuples.:errorif the word break name is not known.
Examples
iex> Unicode.WordBreak.fetch(:zwj)
{:ok, [{8205, 8205}]}
iex> Unicode.WordBreak.fetch(:invalid)
:error
Returns the Unicode codepoint ranges for a given word break.
Aliases are resolved by this function.
Arguments
word_breakis any word break name as an atom, or a string alias for a word break.
Returns
range_listwhich is a list of codepoint ranges as 2-tuples.nilif the word break name is not known.
Examples
iex> Unicode.WordBreak.get(:zwj)
[{8205, 8205}]
iex> Unicode.WordBreak.get(:invalid)
nil
Returns a list of known Unicode word break names.
This function does not return the names of any word break aliases.
Returns
- A list of word break names as atoms.
Examples
iex> Unicode.WordBreak.known_word_breaks() |> Enum.sort() |> Enum.take(3)
[:aletter, :cr, :double_quote]
Returns the word break name(s) for the given binary or codepoint.
Arguments
codepoint_or_stringis either an integer codepoint or a string.
Returns
In the case of a codepoint, a single word break name as an atom. Codepoints with no explicit word break property default to
:xx.In the case of a string, a list of the word break names for each codepoint in the string, in order. One entry is returned for each codepoint.
Examples
iex> Unicode.WordBreak.word_break(0x200D)
:zwj
iex> Unicode.WordBreak.word_break("A")
[:aletter]
Returns the map of Unicode word breaks.
Returns
- A map with the word break name as the key and a list of codepoint ranges as 2-tuples as the value.
Examples
iex> Unicode.WordBreak.word_breaks() |> Map.get(:zwj)
[{8205, 8205}]