Functions to introspect the Unicode grapheme cluster break property for binaries (Strings) and codepoints.
The primary API is grapheme_break/1 which returns the grapheme cluster break property for a codepoint or the list of grapheme cluster break properties for a string.
The functions fetch/1, get/1 and count/1 provide introspection of the codepoint ranges associated with a given grapheme cluster break property. grapheme_breaks/0, known_grapheme_breaks/0 and aliases/0 return the underlying property data.
Summary
Functions
Returns a map of aliases for Unicode grapheme cluster breaks.
Returns the count of the number of characters for a given grapheme cluster break.
Returns the Unicode codepoint ranges for a given grapheme cluster break.
Returns the Unicode codepoint ranges for a given grapheme cluster break.
Returns the grapheme cluster break name(s) for the given binary or codepoint.
Returns the map of Unicode grapheme cluster breaks.
Returns a list of known Unicode grapheme cluster break names.
Functions
Returns a map of aliases for Unicode grapheme cluster breaks.
An alias is an alternative name for referring to a grapheme cluster break. Aliases are resolved by the fetch/1 and get/1 functions.
Returns
- A map with the alias as a string key and the grapheme cluster break name as an atom value.
Examples
iex> Unicode.GraphemeClusterBreak.aliases() |> Map.get("zwj")
:zwj
Returns the count of the number of characters for a given grapheme cluster break.
Arguments
grapheme_breakis any grapheme cluster break name as an atom, or a string alias for a grapheme cluster break.
Returns
The number of codepoints that have the given grapheme cluster break.
:errorif the grapheme cluster break name is not known.
Examples
iex> Unicode.GraphemeClusterBreak.count(:prepend)
27
Returns the Unicode codepoint ranges for a given grapheme cluster break.
Aliases are resolved by this function.
Arguments
grapheme_breakis any grapheme cluster break name as an atom, or a string alias for a grapheme cluster break.
Returns
{:ok, range_list}whererange_listis a list of codepoint ranges as 2-tuples.:errorif the grapheme cluster break name is not known.
Examples
iex> Unicode.GraphemeClusterBreak.fetch(:zwj)
{:ok, [{8205, 8205}]}
iex> Unicode.GraphemeClusterBreak.fetch(:invalid)
:error
Returns the Unicode codepoint ranges for a given grapheme cluster break.
Aliases are resolved by this function.
Arguments
grapheme_breakis any grapheme cluster break name as an atom, or a string alias for a grapheme cluster break.
Returns
range_listwhich is a list of codepoint ranges as 2-tuples.nilif the grapheme cluster break name is not known.
Examples
iex> Unicode.GraphemeClusterBreak.get(:zwj)
[{8205, 8205}]
iex> Unicode.GraphemeClusterBreak.get(:invalid)
nil
Returns the grapheme cluster 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 grapheme cluster break name as an atom. Codepoints with no explicit grapheme cluster break property default to
:other.In the case of a string, a list of the distinct grapheme cluster break names represented by the codepoints in the string.
Examples
iex> Unicode.GraphemeClusterBreak.grapheme_break(0x200D)
:zwj
iex> Unicode.GraphemeClusterBreak.grapheme_break("A")
[:other]
Returns the map of Unicode grapheme cluster breaks.
Returns
- A map with the grapheme cluster break name as the key and a list of codepoint ranges as 2-tuples as the value.
Examples
iex> Unicode.GraphemeClusterBreak.grapheme_breaks() |> Map.get(:zwj)
[{8205, 8205}]
Returns a list of known Unicode grapheme cluster break names.
This function does not return the names of any grapheme cluster break aliases.
Returns
- A list of grapheme cluster break names as atoms.
Examples
iex> Unicode.GraphemeClusterBreak.known_grapheme_breaks() |> Enum.sort() |> Enum.take(3)
[:control, :cr, :extend]