Unicode.Block (Unicode v2.0.0)

Copy Markdown View Source

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

aliases()

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

assigned()

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}

block(string)

Returns the block name(s) for the given binary or codepoint.

Arguments

  • string_or_codepoint is either a binary (String) or a codepoint in the range 0..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]

blocks()

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}]

count(block)

Returns the count of characters in a given block.

Aliases are resolved by this function.

Arguments

  • block is any block name or alias, as an atom or string.

Returns

  • A non-negative integer count of the codepoints in the block.

  • :error if the block is not known.

Examples

iex> Unicode.Block.count(:old_north_arabian)
32

fetch(block)

Returns the Unicode codepoint ranges for a given block.

Aliases are resolved by this function.

Arguments

  • block is any block name or alias, as an atom or string.

Returns

  • {:ok, range_list} where range_list is a list of codepoint ranges as 2-tuples.

  • :error if the block is not known.

Examples

iex> Unicode.Block.fetch(:basic_latin)
{:ok, [{0, 127}]}

iex> Unicode.Block.fetch(:invalid)
:error

get(block)

Returns the Unicode codepoint ranges for a given block.

Aliases are resolved by this function.

Arguments

  • block is any block name or alias, as an atom or string.

Returns

  • A list of codepoint ranges as 2-tuples.

  • nil if the block is not known.

Examples

iex> Unicode.Block.get(:basic_latin)
[{0, 127}]

iex> Unicode.Block.get(:invalid)
nil

known_blocks()

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