Unicode.NfcQuickCheck (Unicode v2.1.0)

Copy Markdown View Source

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

The NFC_Quick_Check property is used by the quick check algorithm of UAX #15 to determine whether a string is already in Normalization Form C. The values are :no and :maybe; codepoints that are always allowed in NFC have the default value :yes.

The primary API is nfc_quick_check/1 which returns the value of a codepoint, or the list of values of a string.

Summary

Functions

Returns a map of aliases for NFC_Quick_Check values.

Returns the count of the codepoints with a given NFC_Quick_Check value.

Returns the codepoint ranges for a given NFC_Quick_Check value.

Returns the codepoint ranges for a given NFC_Quick_Check value.

Returns a list of known NFC_Quick_Check values.

Returns the map of NFC_Quick_Check values to codepoint ranges.

Returns the NFC_Quick_Check value of the given binary or codepoint.

Functions

aliases()

Returns a map of aliases for NFC_Quick_Check values.

Returns

  • A map where the alias string is the key and the value is the atom value.

Examples

iex> Unicode.NfcQuickCheck.aliases() |> Map.get("n")
:no

count(value)

Returns the count of the codepoints with a given NFC_Quick_Check value.

Aliases are resolved by this function.

Arguments

  • value is any value name or alias, as an atom or string.

Returns

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

  • :error if the value is not known.

Examples

iex> is_integer(Unicode.NfcQuickCheck.count(:no))
true

fetch(value)

Returns the codepoint ranges for a given NFC_Quick_Check value.

Aliases are resolved by this function.

Arguments

  • value is any value name or alias, as an atom or string.

Returns

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

  • :error if the value is not known.

Examples

iex> Unicode.NfcQuickCheck.fetch(:no) |> elem(0)
:ok

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

get(value)

Returns the codepoint ranges for a given NFC_Quick_Check value.

Aliases are resolved by this function.

Arguments

  • value is any value name or alias, as an atom or string.

Returns

  • A list of codepoint ranges as 2-tuples.

  • nil if the value is not known.

Examples

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

known_nfc_quick_check()

Returns a list of known NFC_Quick_Check values.

Returns

  • A list of atom values.

Examples

iex> :maybe in Unicode.NfcQuickCheck.known_nfc_quick_check()
true

nfc_quick_check()

Returns the map of NFC_Quick_Check values to codepoint ranges.

Returns

  • A map where the quick check value (:no or :maybe) is the key and a list of codepoint ranges as 2-tuples is the value.

Examples

iex> Unicode.NfcQuickCheck.nfc_quick_check() |> Map.keys() |> Enum.sort()
[:maybe, :no]

nfc_quick_check(string)

Returns the NFC_Quick_Check 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, :no, :maybe or the default :yes.

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

Examples

iex> Unicode.NfcQuickCheck.nfc_quick_check(?A)
:yes

iex> Unicode.NfcQuickCheck.nfc_quick_check(0x0300)
:maybe