Functions to introspect the Unicode Script_Extensions property for binaries (Strings) and codepoints.
The Script_Extensions property (scx) records the scripts a codepoint is commonly used with, which for shared characters is more than one (see UAX #24). U+0640 ARABIC TATWEEL, for example, has Script value :common but is used with Arabic, Syriac, Mandaic and others; its Script_Extensions value names each of them. Matching on Script_Extensions rather than Script is required for UTS #18 RL1.2 conformance.
The property is set-valued: each codepoint maps to a set of scripts. This module inverts that mapping so a codepoint appears under every script in its set, which is both the shape the other property modules use and the form queries actually take — script_extensions(:latin) answers "which codepoints have Latin in their set?".
Two consequences of UAX #24 are worth knowing:
A codepoint absent from the
Script_Extensionsdata takes itsScriptvalue, so this module returns a superset ofUnicode.Scriptfor most scripts rather than only the explicitly listed characters.For a codepoint that is listed, the listed set replaces its
Scriptvalue. U+00B7 MIDDLE DOT hasScriptvalue:common, but:commonis not in itsScript_Extensionsset, so it is absent fromscript_extensions(:common).
The primary API is script_extensions/1 which returns the scripts of a codepoint, or of a string.
Summary
Functions
Returns a map of aliases for Unicode script extensions.
Returns the count of the codepoints having a given script in their Script_Extensions set.
Returns the Unicode codepoint ranges for a given script extension.
Returns the Unicode codepoint ranges for a given script extension.
Returns a list of known Unicode script names for the Script_Extensions property.
Returns the map of Unicode script extensions.
Returns the Script_Extensions set of the given binary or codepoint.
Functions
Returns a map of aliases for Unicode script extensions.
The Script_Extensions property takes Script property values, so the Script aliases apply
here unchanged — "latn" and "latin" both resolve to :latin.
Returns
- A map where the alias string is the key and the script name is the value.
Examples
iex> Unicode.ScriptExtensions.aliases() |> Map.get("latn")
:latin
Returns the count of the codepoints having a given script in their Script_Extensions set.
Aliases are resolved by this function.
Arguments
scriptis any script name or alias, as an atom or string.
Returns
A non-negative integer count of the codepoints with the script extension.
:errorif the script is not known.
Examples
iex> Unicode.ScriptExtensions.count(:latin)
1720
iex> Unicode.ScriptExtensions.count(:bopomofo)
122
Returns the Unicode codepoint ranges for a given script extension.
Aliases are resolved by this function.
Arguments
scriptis any script name or alias, as an atom or string.
Returns
{:ok, range_list}whererange_listis a list of codepoint ranges as 2-tuples.:errorif the script is not known.
Examples
iex> Unicode.ScriptExtensions.fetch(:latin) |> elem(0)
:ok
iex> Unicode.ScriptExtensions.fetch(:invalid)
:error
Returns the Unicode codepoint ranges for a given script extension.
Aliases are resolved by this function.
Arguments
scriptis any script name or alias, as an atom or string.
Returns
A list of codepoint ranges as 2-tuples.
nilif the script is not known.
Examples
iex> Unicode.ScriptExtensions.get("latn") |> is_list()
true
iex> Unicode.ScriptExtensions.get(:invalid)
nil
Returns a list of known Unicode script names for the Script_Extensions property.
Returns
- A list of atom script names.
Examples
iex> :latin in Unicode.ScriptExtensions.known_script_extensions()
true
Returns the map of Unicode script extensions.
Returns
- A map where the script name is the key and a list of codepoint ranges as 2-tuples is the value.
Examples
iex> Unicode.ScriptExtensions.script_extensions() |> Map.fetch!(:latin) |> is_list()
true
Returns the Script_Extensions set 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, the list of script name atoms in its
Script_Extensionsset, sorted. An unassigned codepoint returns[:unknown].For a binary, the sorted union of the sets of the codepoints in the binary.
Examples
iex> Unicode.ScriptExtensions.script_extensions(?A)
[:latin]
iex> Unicode.ScriptExtensions.script_extensions(0x02C7)
[:bopomofo, :latin]
iex> Unicode.ScriptExtensions.script_extensions("Aά")
[:greek, :latin]