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