Functions to introspect the Unicode script property for binaries (Strings) and codepoints.
The primary API is script/1 which returns the script of a codepoint, or the list of scripts of a string.
The functions fetch/1, get/1 and count/1 provide introspection of the codepoint ranges belonging to a script. scripts/0, known_scripts/0 and aliases/0 return the underlying script data.
Summary
Functions
Returns a map of aliases for Unicode scripts.
Returns the count of characters in a given script.
Returns the Unicode codepoint ranges for a given script.
Returns the Unicode codepoint ranges for a given script.
Returns a list of known Unicode script names.
Returns the script name(s) for the given binary or codepoint.
Returns the map of Unicode scripts.
Functions
Returns a map of aliases for Unicode scripts.
An alias is an alternative name for referring to a script. Aliases are resolved by the fetch/1 and get/1 functions.
Returns
- A map where the alias string is the key and the script name is the value.
Examples
iex> Unicode.Script.aliases() |> Map.get("ogam")
:ogham
Returns the count of characters in a given script.
Aliases are resolved by this function.
Arguments
scriptis any script name or alias, as an atom or string.
Returns
A non-negative integer count of the codepoints in the script.
:errorif the script is not known.
Examples
iex> Unicode.Script.count("mongolian")
168
Returns the Unicode codepoint ranges for a given script.
Aliases are resolved by this function.
Arguments
scriptis any script name or alias, as an atom or string.
Returns
{:ok, range_list}whererange_listis a list of codepoint ranges as 2-tuples.:errorif the script is not known.
Examples
iex> Unicode.Script.fetch(:ogham)
{:ok, [{5760, 5788}]}
iex> Unicode.Script.fetch(:invalid)
:error
Returns the Unicode codepoint ranges for a given script.
Aliases are resolved by this function.
Arguments
scriptis any script name or alias, as an atom or string.
Returns
A list of codepoint ranges as 2-tuples.
nilif the script is not known.
Examples
iex> Unicode.Script.get(:ogham)
[{5760, 5788}]
iex> Unicode.Script.get(:invalid)
nil
Returns a list of known Unicode script names.
This function does not return the names of any script aliases.
Returns
- A list of atom script names.
Examples
iex> :latin in Unicode.Script.known_scripts()
true
Returns the script 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 script name is returned.
For a binary, a list of the distinct script names of the codepoints in the binary is returned.
Examples
iex> Unicode.Script.script(?A)
:latin
iex> Unicode.Script.script("abc")
[:latin]
Returns the map of Unicode scripts.
Returns
- A map where the script name is the key and a list of codepoint ranges as 2-tuples is the value.
Examples
iex> Unicode.Script.scripts() |> Map.get(:ogham)
[{5760, 5788}]