Resolves Unicode character names to their codepoint.
Names are taken from the Name field of the Unicode Character Database
(UnicodeData.txt) and matched loosely: case, whitespace, _ and - are
ignored (as in \N{...} name lookups). Codepoints whose name is a bracketed
label such as <control>, or an algorithmically-named range (CJK ideographs,
Hangul syllables), are not included.
The names are prefix-compressed (front-coded) into a single sorted binary blob with block restart points, and looked up with a binary search over the restart names followed by a scan-decode within one block. This keeps the table compact (about 0.4MB resident at runtime, versus roughly 1.2MB uncompressed) without materialising a large map.
Summary
Functions
Returns the number of names in the table.
Returns the codepoint for a Unicode character name.
Functions
@spec count() :: non_neg_integer()
Returns the number of names in the table.
@spec to_codepoint(String.t()) :: {:ok, pos_integer()} | :error
Returns the codepoint for a Unicode character name.
Arguments
nameis a Unicode character name as a string, matched loosely.
Returns
{:ok, codepoint}or:errorif the name is not known.
Examples
iex> Unicode.CharacterName.to_codepoint("LATIN SMALL LETTER A")
{:ok, 97}
iex> Unicode.CharacterName.to_codepoint("bullet")
{:ok, 8226}
iex> Unicode.CharacterName.to_codepoint("Not A Real Name")
:error