silk.text.regex_unicode.

Unicode 17.0.0 case folding, property and range tables for silk.text.regex.

When to use#

Use silk.text.regex in application code. This module is the regular-expression engine's Unicode support: ECMAScript case folding, the property sets \p{...} names, and the range arithmetic that builds character classes.

Details#

The tables are compact range encodings, generated from the Unicode 17.0.0 Character Database (Unicode License v3) by SilkJS's scripts/generate_unicode.py. The encoding started from QuickJS, Copyright (c) 2017-2021 Fabrice Bellard and Charlie Gordon, under the MIT license in licenses/quickjs.txt.

Public declarations: 6.

CaseMapping#

silk
pub struct CaseMapping

The full Unicode case-fold mapping of one scalar, with at most three scalar values. Only the first length entries of points are part of the result.

Field points#

silk
pub points: [u32; 3]

The mapped scalars, followed by zero entries that are not part of the result.

Field length#

silk
pub length: usize

The number of mapped scalars, from one through three.

UnicodeCase#

silk
pub struct UnicodeCase

ECMAScript case canonicalization and character classes over Unicode scalars.

Implementation UnicodeCase#

silk
impl UnicodeCase

Associated function fold#

silk
pub fn fold(c: u32) -> CaseMapping

Returns the full, locale-independent Unicode 17.0.0 case fold of c.

Details#

The result contains one through three scalars. An unmapped value is returned unchanged. Use this mapping for caseless text comparison; it can expand one scalar into several scalars.

Associated function canonicalize#

silk
pub fn canonicalize(c: u32, isUnicode: bool) -> u32

Applies ECMAScript RegExp canonicalization, which never expands a code point.

Associated function isSpace#

silk
pub fn isSpace(code: u32) -> bool

Tests ECMAScript whitespace, including BOM but excluding NEXT LINE.

Associated function isWordByte#

silk
pub fn isWordByte(code: u32) -> bool

Tests the ASCII word characters \w matches: letters, digits and _.

Associated function isIdentifierStart#

silk
pub fn isIdentifierStart(code: u32) -> bool

Tests whether code can start an ECMAScript identifier, as a capture name requires.

Associated function isIdentifierContinue#

silk
pub fn isIdentifierContinue(code: u32) -> bool

Tests whether code can continue an ECMAScript identifier, including ZWNJ and ZWJ.

UnknownProperty#

silk
pub struct UnknownProperty

The failure for a property name or value that is not an exact supported alias.

UnicodeProperties#

silk
pub struct UnicodeProperties

The character sets that \p{...} and \P{...} name.

Implementation UnicodeProperties#

silk
impl UnicodeProperties

Associated function isScriptName#

silk
pub static fn isScriptName(name: string) -> bool

Returns whether name is a script name or alias that \p{Script=name} accepts.

Details#

A static function, for checking a pattern while it compiles. It reads the name table the engine's own script lookup reads.

Associated function isCategoryName#

silk
pub static fn isCategoryName(name: string) -> bool

Returns whether name is a general category name or alias that \p{gc=name} accepts.

Details#

A static function, for checking a pattern while it compiles. It reads the name table the engine's own category lookup reads.

Associated function isBinaryName#

silk
pub static fn isBinaryName(name: string) -> bool

Returns whether name is a binary property name or alias that \p{name} accepts.

Details#

A static function, for checking a pattern while it compiles. It reads the name table the engine's own property lookup reads, and admits only the properties it can build.

Associated function script#

silk
pub effect fn script(name: string, extensions: bool) -> CharRange
    ! OutOfMemoryError | UnknownProperty
    ? &mut Allocator

Resolves exact Unicode script names and aliases; optionally applies Script_Extensions.

Errors#

  • UnknownProperty if name is not an exact supported alias.

  • OutOfMemoryError if the allocator cannot supply the set.

Associated function generalCategory#

silk
pub effect fn generalCategory(name: string) -> CharRange
    ! OutOfMemoryError | UnknownProperty
    ? &mut Allocator

Resolves exact short/long category aliases and aggregate categories.

Errors#

  • UnknownProperty if name is not an exact supported alias.

  • OutOfMemoryError if the allocator cannot supply the set.

Associated function property#

silk
pub effect fn property(name: string) -> CharRange
    ! OutOfMemoryError | UnknownProperty
    ? &mut Allocator

Resolves the supported binary property names and aliases.

Errors#

  • UnknownProperty if name is not an exact supported alias.

  • OutOfMemoryError if the allocator cannot supply the set.

Associated function sequences#

silk
pub effect fn sequences<'env, E, ? R>(
    name: string,
    mut visit: for<use 'call> mut fn<'env>(&[u32]) -> once Effect<'call & 'env; () ! E ? R>,
  ) -> ()
    ! OutOfMemoryError | UnknownProperty | E
    ? &mut Allocator | R

Visits all sequences in upstream order. The borrowed stack buffer lasts only for the call.

Errors#

  • UnknownProperty if name is not an exact supported alias.

  • Any failure of visit.

  • OutOfMemoryError if the allocator cannot supply the set.

RangeOperation#

silk
pub enum RangeOperation

How CharRange.apply combines two sets.

Union#

silk
Union

Characters in either set.

Intersection#

silk
Intersection

Characters in both sets.

Xor#

silk
Xor

Characters in exactly one set.

Subtract#

silk
Subtract

Characters in the first set and not the second.

CharRange#

silk
pub struct CharRange

Sorted, disjoint half-open intervals over u32 character values. Inversion uses an exclusive UINT32_MAX sentinel, not 0x110000.

Implementation CharRange#

silk
impl CharRange

Associated function make#

silk
pub fn make() -> CharRange

Returns an empty set.

Method points#

silk
pub fn points(self: &Self) -> &[u32]

Returns the interval boundaries: each even index starts an interval, each odd index ends one.

Method clear#

silk
pub fn clear(self: &mut Self) -> ()

Removes every interval and keeps the storage.

Method reserve#

silk
pub effect fn reserve(self: &mut Self, additional: usize) -> ()
    ! OutOfMemoryError
    ? &mut Allocator

Reserves room for additional more boundaries.

Errors#

  • OutOfMemoryError if the allocator cannot grow the storage.

Method addInterval#

silk
pub effect fn addInterval(self: &mut Self, start: u32, end: u32) -> ()
    ! OutOfMemoryError
    ? &mut Allocator

Unions a half-open interval, merging overlaps and adjacent intervals.

Errors#

  • OutOfMemoryError if the allocator cannot supply the set.

Method unionInterval#

silk
pub effect fn unionInterval(self: &mut Self, first: u32, last: u32) -> ()
    ! OutOfMemoryError
    ? &mut Allocator

Interval union uses inclusive endpoints and unsigned wrapping.

Errors#

  • OutOfMemoryError if the allocator cannot supply the set.

Method apply#

silk
pub effect fn apply(self: &mut Self, other: &CharRange, operation: RangeOperation) -> ()
    ! OutOfMemoryError
    ? &mut Allocator

Replaces this set with its combination with other.

Errors#

  • OutOfMemoryError if the allocator cannot supply the result.

Method invert#

silk
pub effect fn invert(self: &mut Self) -> ()
    ! OutOfMemoryError
    ? &mut Allocator

Replaces this set with its complement over all u32 values.

Errors#

  • OutOfMemoryError if the allocator cannot grow the storage.

Method canonicalize#

silk
pub effect fn canonicalize(self: &mut Self, isUnicode: bool) -> ()
    ! OutOfMemoryError
    ? &mut Allocator

Canonicalizes only case-changing table runs, never the whole character domain.

Errors#

  • OutOfMemoryError if the allocator cannot supply 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.

View the source of this page