Unicode.NumericType (Unicode v2.2.0)

Copy Markdown View Source

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

The Numeric_Type property classifies how a codepoint represents a number. The values are :decimal, :digit and :numeric; codepoints that are not numeric have the value :none.

The primary API is numeric_type/1 which returns the numeric type of a codepoint, or the list of numeric types of a string. See Unicode.NumericValue for the associated numeric values.

Summary

Functions

Returns a map of aliases for Unicode numeric types.

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

Returns the Unicode codepoint ranges for a given numeric type.

Returns the Unicode codepoint ranges for a given numeric type.

Returns a list of known Unicode numeric type names.

Returns the numeric type of the given binary or codepoint.

Returns the map of Unicode numeric types.

Functions

aliases()

Returns a map of aliases for Unicode numeric types.

Returns

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

Examples

iex> Unicode.NumericType.aliases() |> Map.get("de")
:decimal

count(numeric_type)

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

Aliases are resolved by this function.

Arguments

  • numeric_type is any numeric type name or alias, as an atom or string.

Returns

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

  • :error if the numeric type is not known.

Examples

iex> Unicode.NumericType.count(:decimal)
770

fetch(numeric_type)

Returns the Unicode codepoint ranges for a given numeric type.

Aliases are resolved by this function.

Arguments

  • numeric_type is any numeric 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 numeric type is not known.

Examples

iex> Unicode.NumericType.fetch(:decimal) |> elem(0)
:ok

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

get(numeric_type)

Returns the Unicode codepoint ranges for a given numeric type.

Aliases are resolved by this function.

Arguments

  • numeric_type is any numeric type name or alias, as an atom or string.

Returns

  • A list of codepoint ranges as 2-tuples.

  • nil if the numeric type is not known.

Examples

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

known_numeric_types()

Returns a list of known Unicode numeric type names.

Returns

  • A list of atom numeric type names.

Examples

iex> :decimal in Unicode.NumericType.known_numeric_types()
true

numeric_type(string)

Returns the numeric 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 numeric type atom is returned. Non-numeric codepoints return :none.

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

Examples

iex> Unicode.NumericType.numeric_type(?1)
:decimal

iex> Unicode.NumericType.numeric_type(?A)
:none

iex> Unicode.NumericType.numeric_type(?½)
:numeric

numeric_types()

Returns the map of Unicode numeric types.

Returns

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

Examples

iex> Unicode.NumericType.numeric_types() |> Map.keys() |> Enum.sort()
[:decimal, :digit, :none, :numeric]