Functions to introspect the Unicode bidirectional (bidi) class property for binaries (Strings) and codepoints.
The primary API is bidi_class/1 which returns the bidi class of a codepoint, or the list of bidi classes of a string.
The functions fetch/1, get/1 and count/1 provide introspection of the codepoint ranges belonging to a bidi class. bidi_classes/0, known_bidi_classes/0 and aliases/0 return the underlying bidi class data.
Summary
Functions
Returns a map of aliases for Unicode bidi classes.
Returns the bidi class name(s) for the given binary or codepoint.
Returns the map of Unicode bidi classes.
Returns the count of characters in a given bidi class.
Returns the Unicode codepoint ranges for a given bidi class.
Returns the Unicode codepoint ranges for a given bidi class.
Returns a list of known Unicode bidi class names.
Functions
Returns a map of aliases for Unicode bidi classes.
An alias is an alternative name for referring to a bidi class. Aliases are resolved by the fetch/1 and get/1 functions.
Returns
- A map where the alias string is the key and the bidi class name is the value.
Examples
iex> Unicode.BidiClass.aliases() |> Map.get("arabicletter")
:al
Returns the bidi class name(s) for the given binary or codepoint.
Arguments
string_or_codepointis either a binary (String) or a codepoint in the range0..0x10FFFF.
Returns
For a codepoint, a single bidi class name is returned.
For a binary, a list of the distinct bidi class names of the codepoints in the binary is returned.
Examples
iex> Unicode.BidiClass.bidi_class(?A)
:l
iex> Unicode.BidiClass.bidi_class(0x05D0)
:r
iex> Unicode.BidiClass.bidi_class(0x0627)
:al
iex> Unicode.BidiClass.bidi_class("abc")
[:l]
Returns the map of Unicode bidi classes.
Returns
- A map where the bidi class name is the key and a list of codepoint ranges as 2-tuples is the value.
Examples
iex> Unicode.BidiClass.bidi_classes() |> Map.get(:lre)
[{8234, 8234}]
Returns the count of characters in a given bidi class.
Aliases are resolved by this function.
Arguments
bidi_classis any bidi class name or alias, as an atom or string.
Returns
A non-negative integer count of the codepoints in the bidi class.
:errorif the bidi class is not known.
Examples
iex> Unicode.BidiClass.count(:al)
1478
Returns the Unicode codepoint ranges for a given bidi class.
Aliases are resolved by this function.
Arguments
bidi_classis any bidi class name or alias, as an atom or string.
Returns
{:ok, range_list}whererange_listis a list of codepoint ranges as 2-tuples.:errorif the bidi class is not known.
Examples
iex> Unicode.BidiClass.fetch(:lre)
{:ok, [{8234, 8234}]}
iex> Unicode.BidiClass.fetch(:invalid)
:error
Returns the Unicode codepoint ranges for a given bidi class.
Aliases are resolved by this function.
Arguments
bidi_classis any bidi class name or alias, as an atom or string.
Returns
A list of codepoint ranges as 2-tuples.
nilif the bidi class is not known.
Examples
iex> Unicode.BidiClass.get(:lre)
[{8234, 8234}]
iex> Unicode.BidiClass.get(:invalid)
nil
Returns a list of known Unicode bidi class names.
This function does not return the names of any class aliases.
Returns
- A list of atom bidi class names.
Examples
iex> :l in Unicode.BidiClass.known_bidi_classes()
true