silk.text.unicode_script.
Unicode scripts as ISO 15924 values, and the Script and Script_Extensions properties, with data from Unicode 18.0.0.
When to use#
Use Script.of to find the script of a character, such as Latin or Arabic. Use
Script.extensions when a character is shared by several scripts, such as the Arabic comma.
Use Script.parse to read a four-letter script code from text.
Details#
A Script holds a big-endian ISO 15924 tag: Latn is 0x4c61746e. The lookups take a code
point as a u32 and do not allocate. A code point with no script, or a value past U+10FFFF,
gets Zzzz (Unknown). Common characters get Zyyy and inherited marks get Zinh.
Examples#
Read the script of a character#
import silk.core.option { Option }
import silk.text.unicode_script { Script }
pub fn main() -> i32 {
let latin = Script.parse("Latn") |> Option<Script>.unwrapOr(Script.unknown())
let letter = Script.of(0x41)
if &letter != &latin {
return 1
}
// U+060C ARABIC COMMA is shared by Arabic, Syriac, Thaana and other scripts.
let arabic = Script.parse("Arab") |> Option<Script>.unwrapOr(Script.unknown())
if !Script.extensions(0x60c).contains(arabic) {
return 1
}
return 0
}Import as Script with import silk.text.unicode_script { Script }.
Public declarations: 2.
Script#
pub struct ScriptA Unicode script, held as its big-endian ISO 15924 tag.
Details#
value holds the four ASCII letters of the tag, first letter in the highest byte: Latn is
0x4c61746e. Script.of gives the script of a code point. Two scripts are equal when their
tags are equal.
Field value#
pub value: u32The big-endian ISO 15924 tag, such as 0x4c61746e for Latn.
Implementation Copy for Script#
impl Copy for ScriptImplementation Equal for Script#
impl Equal for ScriptOperation equals#
equals: Script.sameImplementation Script#
impl ScriptAssociated function unknown#
pub fn unknown() -> ScriptReturns Zzzz (Unknown), the script of characters that Unicode does not assign to a script.
Associated function common#
pub fn common() -> ScriptReturns Zyyy (Common), the script of characters that several scripts use, such as digits and
punctuation.
Associated function inherited#
pub fn inherited() -> ScriptReturns Zinh (Inherited), the script of combining marks that take the script of their base
character.
Associated function of#
pub fn of(cp: u32) -> ScriptReturns the Unicode Script property of the code point cp. A code point with no script, or
a value past U+10FFFF, gives Script.unknown.
Associated function extensions#
pub fn extensions(cp: u32) -> ScriptSetReturns the Unicode Script_Extensions property of the code point cp: each script that
uses the character.
Details#
A character without an explicit Script_Extensions value gets the set with only its
Script.of value. The set is sorted by tag and borrows static data, so the call does not
allocate.
Associated function fromIso15924Tag#
pub fn fromIso15924Tag(value: u32) -> Option<Script>Returns the script for the ISO 15924 tag value, or None if value is 0.
Details#
The letter case is normalized, so 0x4c41544e (LATN) gives Latn. A value that is not
four ASCII letters gives Script.unknown. Historical and variant tags map to the script
that Unicode uses for their characters: Hans and Hant give Hani, Jamo gives Hang,
Latf and Latg give Latn, Cyrs gives Cyrl, Geok gives Geor, Aran gives Arab,
and Syre, Syrj and Syrn give Syrc.
Associated function parse#
pub fn parse(text: string) -> Option<Script>Returns the script for the ISO 15924 code text, such as "Latn", or None for empty text.
Details#
The function reads the first four bytes of text, pads a shorter code with spaces, and
normalizes it as Script.fromIso15924Tag does: "latn" gives Latn, and a code that is
not four ASCII letters gives Script.unknown.
ScriptSet#
pub struct ScriptSetA set of scripts that borrows static data, as Script.extensions gives it.
Details#
The scripts are sorted by ISO 15924 tag. The set is never empty. It is Copy and does not own
storage.
Implementation Copy for ScriptSet#
impl Copy for ScriptSetImplementation ScriptSet#
impl ScriptSetMethod length#
pub fn length(self: &Self) -> usizeReturns the number of scripts in the set. It is at least 1.
Method get#
pub fn get(self: &Self, index: usize) -> Option<Script>Returns the script at position index, or None if index is not less than
ScriptSet.length. The scripts are sorted by tag.
Method contains#
pub fn contains(self: &Self, script: Script) -> boolReturns true if script is in the set.
Category: Text.
Profiles: aarch64-apple-darwin, aarch64-unknown-linux-gnu, aarch64-unknown-linux-gnu-no-libc, x86_64-unknown-linux-gnu, x86_64-unknown-linux-gnu-no-libc, wasm32-unknown-unknown, wasm32-wasip1, wasm32-wasip2, x86_64-pc-windows-msvc, wasm64-unknown-unknown.