Unicode.DecompositionType (Unicode v2.1.0)

Copy Markdown View Source

Functions to introspect the Unicode Decomposition_Type property for binaries (Strings) and codepoints.

The Decomposition_Type property classifies the kind of decomposition mapping a codepoint has, for example :canonical, :compat, :font, :circle or :nobreak. Codepoints with no decomposition mapping have the value :none.

The primary API is decomposition_type/1 which returns the decomposition type of a codepoint, or the list of decomposition types of a string.

Summary

Functions

Returns a map of aliases for Unicode decomposition types.

Returns the count of the codepoints with a given decomposition type.

Returns the decomposition type of the given binary or codepoint.

Returns the map of Unicode decomposition types.

Returns the Unicode codepoint ranges for a given decomposition type.

Returns the Unicode codepoint ranges for a given decomposition type.

Returns a list of known Unicode decomposition type names.

Functions

aliases()

Returns a map of aliases for Unicode decomposition types.

Returns

  • A map where the alias string is the key and the decomposition type is the value.

Examples

iex> Unicode.DecompositionType.aliases() |> Map.get("can")
:canonical

count(decomposition_type)

Returns the count of the codepoints with a given decomposition type.

Aliases are resolved by this function.

Arguments

  • decomposition_type is any decomposition type name or alias, as an atom or string.

Returns

  • A non-negative integer count of the codepoints with the decomposition type.

  • :error if the decomposition type is not known.

Examples

iex> is_integer(Unicode.DecompositionType.count(:canonical))
true

decomposition_type(string)

Returns the decomposition type of 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 decomposition type atom is returned. Codepoints with no decomposition mapping return :none.

  • For a binary, a list of the distinct decomposition types of the codepoints in the binary is returned.

Examples

iex> Unicode.DecompositionType.decomposition_type(0x00A0)
:nobreak

iex> Unicode.DecompositionType.decomposition_type(?A)
:none

decomposition_types()

Returns the map of Unicode decomposition types.

Returns

  • A map where the decomposition type is the key and a list of codepoint ranges as 2-tuples is the value.

Examples

iex> :canonical in Map.keys(Unicode.DecompositionType.decomposition_types())
true

fetch(decomposition_type)

Returns the Unicode codepoint ranges for a given decomposition type.

Aliases are resolved by this function.

Arguments

  • decomposition_type is any decomposition type 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 decomposition type is not known.

Examples

iex> Unicode.DecompositionType.fetch(:canonical) |> elem(0)
:ok

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

get(decomposition_type)

Returns the Unicode codepoint ranges for a given decomposition type.

Aliases are resolved by this function.

Arguments

  • decomposition_type is any decomposition type name or alias, as an atom or string.

Returns

  • A list of codepoint ranges as 2-tuples.

  • nil if the decomposition type is not known.

Examples

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

known_decomposition_types()

Returns a list of known Unicode decomposition type names.

Returns

  • A list of atom decomposition type names.

Examples

iex> :compat in Unicode.DecompositionType.known_decomposition_types()
true