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

result()

@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.

status()

@type status() :: :valid | :ignored | :mapped | :deviation | :disallowed

An IDNA mapping table status.

Functions

lookup(codepoint)

@spec lookup(non_neg_integer()) :: result()

Returns the IDNA mapping table status (and replacement, if any) for a single Unicode code point.

Arguments

  • codepoint is a non-negative integer in the range 0..0x10FFFF.

Returns

  • {status, replacement} where status is one of :valid, :ignored, :mapped, :deviation or :disallowed, and replacement is a (possibly empty) list of target code points for :mapped and :deviation, or nil for 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}