Unicode. IDNA. Mapping
(Unicode IDNA v0.2.0)
View Source
UTS #46 IDNA mapping table lookup.
The mapping table classifies every Unicode code point into one of
five statuses (:valid, :ignored, :mapped, :deviation or
:disallowed) and, for :mapped and :deviation, supplies the
list of target code points to substitute.
This module compiles the table from data/idna_mapping_table.txt
at compile time and exposes a single fast-path lookup function.
Summary
Types
A mapping result. The second element is nil for :valid, :ignored
and :disallowed, and a (possibly empty) list of target code points
for :mapped and :deviation.
An IDNA mapping table status.
Functions
Returns the IDNA mapping table status (and replacement, if any) for a single Unicode code point.
Types
@type result() :: {status(), [non_neg_integer()] | nil}
A mapping result. The second element is nil for :valid, :ignored
and :disallowed, and a (possibly empty) list of target code points
for :mapped and :deviation.
@type status() :: :valid | :ignored | :mapped | :deviation | :disallowed
An IDNA mapping table status.
Functions
@spec lookup(non_neg_integer()) :: result()
Returns the IDNA mapping table status (and replacement, if any) for a single Unicode code point.
Arguments
codepointis a non-negative integer in the range0..0x10FFFF.
Returns
{status, replacement}wherestatusis one of:valid,:ignored,:mapped,:deviationor:disallowed, andreplacementis a (possibly empty) list of target code points for:mappedand:deviation, ornilfor the other statuses.
Examples
iex> Unicode.IDNA.Mapping.lookup(?A)
{:mapped, [?a]}
iex> Unicode.IDNA.Mapping.lookup(?a)
{:valid, nil}
iex> Unicode.IDNA.Mapping.lookup(0x0080)
{:disallowed, nil}
iex> Unicode.IDNA.Mapping.lookup(0x00DF)
{:deviation, [?s, ?s]}
iex> Unicode.IDNA.Mapping.lookup(0x00AD)
{:ignored, nil}