std.unicode
Sets of code points, Unicode properties, simple case folding and grapheme clusters (Unicode 16.0.0).
A set of code points is a List[(Int, Int)] of inclusive ranges, sorted, neither overlapping nor touching.
Graphemes
Section titled “Graphemes”type Graphemes = { points: CodePoints, pending: Option[Int] }An iterator over a string’s extended grapheme clusters (UAX #29), each as
a string, from s.graphemes().
pending is the code point that ended the last cluster and starts the
next.
Traits
Section titled “Traits”GraphemeText
Section titled “GraphemeText”trait GraphemeText { fn graphemes(self) -> Graphemes}A string’s graphemes as an iterator: s.graphemes().
Functions
Section titled “Functions”symmetric_difference
Section titled “symmetric_difference”fn symmetric_difference( a: List[(Int, Int)], b: List[(Int, Int)],) -> List[(Int, Int)]Every code point in exactly one of a and b.
difference
Section titled “difference”fn difference(a: List[(Int, Int)], b: List[(Int, Int)]) -> List[(Int, Int)]Every code point in a but not in b.
previous_code
Section titled “previous_code”fn previous_code(c: Int) -> IntThe code point before c, skipping the surrogates.
next_code
Section titled “next_code”fn next_code(c: Int) -> IntThe code point after c, skipping the surrogates U+D800 to U+DFFF. So no
set operation starts or ends a range on a surrogate.
fn union(a: List[(Int, Int)], b: List[(Int, Int)]) -> List[(Int, Int)]Every code point in a or b.
canonical
Section titled “canonical”fn canonical(rs: List[(Int, Int)]) -> List[(Int, Int)]Sorts any ranges and merges those that overlap or touch.
intersect
Section titled “intersect”fn intersect(a: List[(Int, Int)], b: List[(Int, Int)]) -> List[(Int, Int)]Every code point in both a and b.
case_folding
Section titled “case_folding”fn case_folding() -> List[(Int, List[Int])]Simple case folding: each code point that has others in its case class, with those others, in order.
has_case_folding
Section titled “has_case_folding”fn has_case_folding(c: Int) -> BoolWhether the code point c has other characters in its case class.
case_fold
Section titled “case_fold”fn case_fold(a: List[(Int, Int)]) -> List[(Int, Int)]a closed under simple case folding: every code point in a, and every
other code point of the same case class.
ascii_case_fold
Section titled “ascii_case_fold”fn ascii_case_fold(a: List[(Int, Int)]) -> List[(Int, Int)]a closed under ASCII case folding, a-z with A-Z.
perl_word
Section titled “perl_word”fn perl_word() -> List[(Int, Int)]\w: word characters. Alphabetic, marks, Nd, Pc and Join_Control.
decode
Section titled “decode”fn decode(table: String) -> List[(Int, Int)]Reads a table of std.unicode_tables. Each range is two numbers: the gap since the previous range’s end + 1, then its length - 1.
is_white_space
Section titled “is_white_space”fn is_white_space(c: Int) -> BoolWhether c is White_Space, as Rust’s char::is_whitespace.
contains_code
Section titled “contains_code”fn contains_code(a: List[(Int, Int)], c: Int) -> BoolWhether the code point c is in a.
perl_space
Section titled “perl_space”fn perl_space() -> List[(Int, Int)]\s: White_Space.
is_alphanumeric
Section titled “is_alphanumeric”fn is_alphanumeric(c: Int) -> BoolWhether c is Alphabetic or a number, as Rust’s char::is_alphanumeric.
is_alphabetic
Section titled “is_alphabetic”fn is_alphabetic(c: Int) -> BoolWhether c is Alphabetic, as Rust’s char::is_alphabetic.
perl_digit
Section titled “perl_digit”fn perl_digit() -> List[(Int, Int)]\d: decimal digits, the general category Nd.
max_code
Section titled “max_code”fn max_code() -> Int where it == 1114111The largest code point.
negate
Section titled “negate”fn negate(a: List[(Int, Int)]) -> List[(Int, Int)]Every code point not in a.
property
Section titled “property”fn property(name: String) -> Result[List[(Int, Int)], String]The code points of \p{name}, matched loosely (normalize).
name is a binary property (Alphabetic), a general category (L,
Letter, Lu), a script (Greek), Any, ASCII or Assigned.
normalize
Section titled “normalize”fn normalize(name: String) -> StringA property or value name for UAX #44 loose matching: lower case, without a
leading is, spaces, _ or -.
property_value
Section titled “property_value”fn property_value( name: String, value: String,) -> Result[List[(Int, Int)], String]The code points of \p{name=value}.
name is a general category, a script, script extensions, an age, or a
grapheme cluster, word or sentence break property.
An age includes every code point assigned by that version.
grapheme_breaks
Section titled “grapheme_breaks”fn grapheme_breaks() -> List[(Int, Int, Int)]Every range of code points whose Grapheme_Cluster_Break isn’t Other, in
order, as (first, last, kind).
fn flat(a: List[(Int, Int)]) -> List[Int]The ranges of a one after the other: [lo, hi, lo, hi, …], as
contains_bound reads them.
contains_bound
Section titled “contains_bound”fn contains_bound(bounds: List[Int], c: Int) -> BoolWhether the code point c is in the ranges bounds holds, written as
flat writes them.
Implementations
Section titled “Implementations”impl Iterator[String] for Graphemesimpl FiniteIterator[String] for Graphemesimpl GraphemeText for String