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
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
Functions
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()
%{}
Returns the count of the codepoints having a given numeric value.
Arguments
valueis an integer or{numerator, denominator}tuple.
Returns
A non-negative integer count of the codepoints with the value.
:errorif no codepoint has the value.
Examples
iex> Unicode.NumericValue.count(7) > 0
true
Returns the Unicode codepoint ranges having a given numeric value.
Arguments
valueis an integer or{numerator, denominator}tuple.
Returns
{:ok, range_list}whererange_listis a list of codepoint ranges as 2-tuples.:errorif no codepoint has the value.
Examples
iex> Unicode.NumericValue.fetch(7) |> elem(0)
:ok
iex> Unicode.NumericValue.fetch(:invalid)
:error
Returns the Unicode codepoint ranges having a given numeric value.
Arguments
valueis an integer or{numerator, denominator}tuple.
Returns
A list of codepoint ranges as 2-tuples.
nilif no codepoint has the value.
Examples
iex> Unicode.NumericValue.get(:invalid)
nil
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
@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_codepointis either a binary (String) or a codepoint in the range0..0x10FFFF.
Returns
For a codepoint, the numeric value as an integer, a
{numerator, denominator}tuple, ornilif 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
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