Functions to introspect the Unicode Age property for binaries (Strings) and codepoints.
The Age property records the version of Unicode in which a codepoint was first assigned. The value is an atom formed from the version number, for example :"1.1" or :"15.0".
The primary API is age/1 which returns the age of a codepoint, or the list of ages of a string. The functions fetch/1, get/1 and count/1 provide introspection of the codepoint ranges belonging to a given age.
Summary
Functions
Returns the age of the given binary or codepoint.
Returns the map of Unicode ages.
Returns a map of aliases for Unicode ages.
Returns the count of the codepoints assigned in a given age.
Returns the Unicode codepoint ranges for a given age.
Returns the Unicode codepoint ranges for a given age.
Returns a list of known Unicode ages.
Functions
Returns the age 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, a single age atom is returned. Unassigned codepoints return
:unassigned.For a binary, a list of the distinct ages of the codepoints in the binary is returned.
Examples
iex> Unicode.Age.age(?A)
:"1.1"
iex> Unicode.Age.age(0x0378)
:unassigned
Returns the map of Unicode ages.
Returns
- A map where the age (as an atom version number) is the key and a list of codepoint ranges as 2-tuples is the value.
Examples
iex> Unicode.Age.ages() |> Map.get(:"1.1") |> hd()
{0, 501}
Returns a map of aliases for Unicode ages.
An alias is an alternative name for referring to an age. PropertyValueAliases.txt
gives each age a V<major>_<minor> alias, so "V18_0" is an alias for :"18.0".
Alias keys are normalised by downcasing and removing whitespace and underscores,
the same normalisation fetch/1 and get/1 apply to their argument, so "V18_0"
is stored and looked up as "v180". Aliases are resolved by fetch/1 and get/1.
Returns
- A map of age aliases to the canonical age name.
Examples
iex> Unicode.Age.aliases() |> Map.get("v11")
:"1.1"
iex> Unicode.Age.fetch("V18_0") == Unicode.Age.fetch("18.0")
true
Returns the count of the codepoints assigned in a given age.
Arguments
ageis any known age, as an atom or string.
Returns
A non-negative integer count of the codepoints in the age.
:errorif the age is not known.
Examples
iex> Unicode.Age.count(:"1.1")
33979
Returns the Unicode codepoint ranges for a given age.
Arguments
ageis any known age, as an atom or string.
Returns
{:ok, range_list}whererange_listis a list of codepoint ranges as 2-tuples.:errorif the age is not known.
Examples
iex> Unicode.Age.fetch(:"1.1") |> elem(0)
:ok
iex> Unicode.Age.fetch(:invalid)
:error
Returns the Unicode codepoint ranges for a given age.
Arguments
ageis any known age, as an atom or string.
Returns
A list of codepoint ranges as 2-tuples.
nilif the age is not known.
Examples
iex> Unicode.Age.get(:"1.1") |> hd()
{0, 501}
iex> Unicode.Age.get(:invalid)
nil
Returns a list of known Unicode ages.
Returns
- A list of atom version numbers.
Examples
iex> :"1.1" in Unicode.Age.known_ages()
true