Skip to content

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.

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.

trait GraphemeText {
fn graphemes(self) -> Graphemes
}

A string’s graphemes as an iterator: s.graphemes().

fn symmetric_difference(
a: List[(Int, Int)],
b: List[(Int, Int)],
) -> List[(Int, Int)]

Every code point in exactly one of a and b.

fn difference(a: List[(Int, Int)], b: List[(Int, Int)]) -> List[(Int, Int)]

Every code point in a but not in b.

fn previous_code(c: Int) -> Int

The code point before c, skipping the surrogates.

fn next_code(c: Int) -> Int

The 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.

fn canonical(rs: List[(Int, Int)]) -> List[(Int, Int)]

Sorts any ranges and merges those that overlap or touch.

fn intersect(a: List[(Int, Int)], b: List[(Int, Int)]) -> List[(Int, Int)]

Every code point in both a and b.

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.

fn has_case_folding(c: Int) -> Bool

Whether the code point c has other characters in its case class.

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.

fn ascii_case_fold(a: List[(Int, Int)]) -> List[(Int, Int)]

a closed under ASCII case folding, a-z with A-Z.

fn perl_word() -> List[(Int, Int)]

\w: word characters. Alphabetic, marks, Nd, Pc and Join_Control.

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.

fn is_white_space(c: Int) -> Bool

Whether c is White_Space, as Rust’s char::is_whitespace.

fn contains_code(a: List[(Int, Int)], c: Int) -> Bool

Whether the code point c is in a.

fn perl_space() -> List[(Int, Int)]

\s: White_Space.

fn is_alphanumeric(c: Int) -> Bool

Whether c is Alphabetic or a number, as Rust’s char::is_alphanumeric.

fn is_alphabetic(c: Int) -> Bool

Whether c is Alphabetic, as Rust’s char::is_alphabetic.

fn perl_digit() -> List[(Int, Int)]

\d: decimal digits, the general category Nd.

fn max_code() -> Int where it == 1114111

The largest code point.

fn negate(a: List[(Int, Int)]) -> List[(Int, Int)]

Every code point not in a.

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.

fn normalize(name: String) -> String

A property or value name for UAX #44 loose matching: lower case, without a leading is, spaces, _ or -.

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.

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.

fn contains_bound(bounds: List[Int], c: Int) -> Bool

Whether the code point c is in the ranges bounds holds, written as flat writes them.

  • impl Iterator[String] for Graphemes
  • impl FiniteIterator[String] for Graphemes
  • impl GraphemeText for String