Functions to introspect the Unicode line break property for binaries (Strings) and codepoints.
The primary API is line_break/1 which returns the line break property for a codepoint or the list of line break properties for a string.
The functions fetch/1, get/1 and count/1 provide introspection of the codepoint ranges associated with a given line break property. line_breaks/0, known_line_breaks/0 and aliases/0 return the underlying property data.
Summary
Functions
Returns a map of aliases for Unicode line breaks.
Returns the count of the number of characters for a given line break.
Returns the Unicode codepoint ranges for a given line break.
Returns the Unicode codepoint ranges for a given line break.
Returns a list of known Unicode line break names.
Returns the line break name(s) for the given binary or codepoint.
Returns the map of Unicode line breaks.
Functions
Returns a map of aliases for Unicode line breaks.
An alias is an alternative name for referring to a line break. Aliases are resolved by the fetch/1 and get/1 functions.
Returns
- A map with the alias as a string key and the line break name as an atom value.
Examples
iex> Unicode.LineBreak.aliases() |> Map.get("linefeed")
:lf
Returns the count of the number of characters for a given line break.
Arguments
line_breakis any line break name as an atom, or a string alias for a line break.
Returns
The number of codepoints that have the given line break.
:errorif the line break name is not known.
Examples
iex> Unicode.LineBreak.count(:al)
26954
Returns the Unicode codepoint ranges for a given line break.
Aliases are resolved by this function.
Arguments
line_breakis any line break name as an atom, or a string alias for a line break.
Returns
{:ok, range_list}whererange_listis a list of codepoint ranges as 2-tuples.:errorif the line break name is not known.
Examples
iex> Unicode.LineBreak.fetch(:lf)
{:ok, [{10, 10}]}
iex> Unicode.LineBreak.fetch(:invalid)
:error
Returns the Unicode codepoint ranges for a given line break.
Aliases are resolved by this function.
Arguments
line_breakis any line break name as an atom, or a string alias for a line break.
Returns
range_listwhich is a list of codepoint ranges as 2-tuples.nilif the line break name is not known.
Examples
iex> Unicode.LineBreak.get(:lf)
[{10, 10}]
iex> Unicode.LineBreak.get(:invalid)
nil
Returns a list of known Unicode line break names.
This function does not return the names of any line break aliases.
Returns
- A list of line break names as atoms.
Examples
iex> Unicode.LineBreak.known_line_breaks() |> Enum.sort() |> Enum.take(3)
[:ai, :ak, :al]
Returns the line 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 line break name as an atom. Codepoints with no explicit line break property default to
:xx.In the case of a string, a list of the distinct line break names represented by the codepoints in the string.
Examples
iex> Unicode.LineBreak.line_break(?\n)
:lf
iex> Unicode.LineBreak.line_break("a b")
[:al, :sp]
Returns the map of Unicode line breaks.
Returns
- A map with the line break name as the key and a list of codepoint ranges as 2-tuples as the value.
Examples
iex> Unicode.LineBreak.line_breaks() |> Map.get(:lf)
[{10, 10}]