Unicode.NumericValue (Unicode v2.2.0)

Copy Markdown View Source

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

The Numeric_Value property is the numeric value a codepoint represents. Whole numbers are returned as integers and fractions as a {numerator, denominator} tuple. Codepoints with no numeric value return nil.

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

Summary

Types

A Unicode numeric value: an integer, a {numerator, denominator} fraction, or nil.

Functions

Returns an empty map.

Returns the count of the codepoints having a given numeric value.

Returns the Unicode codepoint ranges having a given numeric value.

Returns the Unicode codepoint ranges having a given numeric value.

Returns a list of known Unicode numeric values.

Returns the numeric value of the given binary or codepoint.

Returns the map of Unicode numeric values.

Types

value()

@type value() :: integer() | {integer(), integer()} | nil

A Unicode numeric value: an integer, a {numerator, denominator} fraction, or nil.

Functions

aliases()

Returns an empty map.

The Numeric_Value property has no value aliases; this function exists to satisfy the Unicode.Property.Behaviour.

Returns

  • An empty map.

Examples

iex> Unicode.NumericValue.aliases()
%{}

count(value)

Returns the count of the codepoints having a given numeric value.

Arguments

  • value is an integer or {numerator, denominator} tuple.

Returns

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

  • :error if no codepoint has the value.

Examples

iex> Unicode.NumericValue.count(7) > 0
true

fetch(value)

Returns the Unicode codepoint ranges having a given numeric value.

Arguments

  • value is an integer or {numerator, denominator} tuple.

Returns

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

  • :error if no codepoint has the value.

Examples

iex> Unicode.NumericValue.fetch(7) |> elem(0)
:ok

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

get(value)

Returns the Unicode codepoint ranges having a given numeric value.

Arguments

  • value is an integer or {numerator, denominator} tuple.

Returns

  • A list of codepoint ranges as 2-tuples.

  • nil if no codepoint has the value.

Examples

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

known_numeric_values()

Returns a list of known Unicode numeric values.

Returns

  • A list of integers and {numerator, denominator} tuples.

Examples

iex> 7 in Unicode.NumericValue.known_numeric_values()
true

iex> {1, 2} in Unicode.NumericValue.known_numeric_values()
true

numeric_value(string)

@spec numeric_value(String.t()) :: [value(), ...]
@spec numeric_value(Unicode.codepoint()) :: value()

Returns the numeric value 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, the numeric value as an integer, a {numerator, denominator} tuple, or nil if the codepoint has no numeric value.

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

Examples

iex> Unicode.NumericValue.numeric_value(?7)
7

iex> Unicode.NumericValue.numeric_value(?½)
{1, 2}

iex> Unicode.NumericValue.numeric_value(?A)
nil

numeric_values()

Returns the map of Unicode numeric values.

Returns

  • A map where the numeric value (an integer or {numerator, denominator} tuple) is the key and a list of codepoint ranges as 2-tuples is the value.

Examples

iex> Unicode.NumericValue.numeric_values() |> Map.get(7) |> Enum.any?(fn {first, last} -> ?7 in first..last end)
true