Unicode v0.1.0

Source
Unicode character properties, case, normalization and segmentation

Installation

Add Unicode to the [Dependencies] table of your package's Rux.toml:

[Dependencies]
Unicode = { Namespace = "Rux", Version = "0.1.0" }

Standard packages are declared by hand: the registry does not serve them, so rux add Rux/Unicode cannot add them.

Dependencies

Guide

Unicode character properties, case, normalization and segmentation, from tables generated out of the Unicode 17.0.0 Character Database.

What it provides

  • Properties — the general category, canonical combining class, and the White_Space, Alphabetic and numeric properties, answered by binary search over compressed ranges.
  • Case — simple per-character mappings, the unconditional full mappings, locale-independent full case folding, and NextInCaseOrbit, which walks every value with the same simple folding, such as k, K and the Kelvin sign. The conditional mappings are deliberately absent: they depend on locale or context, and applying them silently is how i stops round-tripping in Turkish.
  • Normalization — canonical and compatibility decomposition (Hangul arithmetically), canonical ordering, and composition: all four normal forms, over scalar-value slices.
  • Graphemes — extended grapheme cluster boundaries by the UAX #29 rules, emoji sequences and regional-indicator pairs included.
  • Scripts — the Script property: ScriptOf gives the Script a scalar belongs to, such as Latin, Greek or Common, and Script::FromName finds one by its long name, matched loosely.

The tables under Src/Generated*.rux are committed output of Tools/UnicodeGen, which records the SHA-256 of every input it read; regenerate with Bin/Tools/rux-unicode-gen after changing the data under Tools/UnicodeGen/Data.

Value model

Unicode scalar values, GeneralCategory, and GraphemeBreak are structural Copy values. Text is borrowed through char32[..] and results are written into caller-owned var char32[..] storage; the package allocates and owns nothing. Length results remain raw writable pointers, so pass an address such as @written. It must be non-null and valid for one uint throughout the call. The slices carry their bounds but not ownership, and their backing storage must outlive the operation.

Example

import Unicode::ToUpperFull;

var output: char32[3];
var written: uint = 0;
ToUpperFull(0xDFu32 as char32, (@output[0])[..3], @written);

Index

Types

NameSummary
GraphemeBreakThe grapheme break class of a scalar value.
GeneralCategoryThe Unicode general category, one per scalar value.
ScriptA script.

Functions

NameSummary
ToUpperSimpleThe simple uppercase of scalar: one value to one, itself when it has no mapping.
ToLowerSimpleThe simple lowercase of scalar.
ToTitleSimpleThe simple titlecase of scalar: the uppercase, except for the few dozen characters whose titlecase differs.
NextInCaseOrbitThe next scalar value that case-insensitive comparison treats as scalar, going round the set of values with the same simple case folding: k, K and the Kelvin sign, or σ, ς and Σ.
ToUpperFullWrites the full uppercase of scalar into into and reports how many values it took.
ToLowerFullWrites the full lowercase of scalar into into.
FoldWrites the full, locale-independent case folding of scalar into into.
GraphemeBreakOfThe break class of scalar.
IsPictographicWhether scalar is an extended pictograph: the emoji and everything reserved to become one.
IsGraphemeBoundaryWhether a cluster boundary falls before index in text.
CountGraphemesHow many grapheme clusters text holds.
DecomposeCanonicalWrites the canonical decomposition of text into into, marks in canonical order: NFD.
DecomposeCompatibilityWrites the compatibility decomposition of text into into, marks in canonical order: NFKD.
NormalizeCanonicalWrites the NFC of text into into: canonical decomposition, canonical order, then composition.
NormalizeCompatibilityWrites the NFKC of text into into: compatibility decomposition, canonical order, then composition.
CategoryOfThe general category of scalar.
CombiningClassOfThe canonical combining class of scalar: zero for nearly everything, and the reordering key for marks.
IsWhiteSpaceWhether scalar is whitespace by Unicode's White_Space property.
IsAlphabeticWhether scalar is alphabetic by the derived Alphabetic property.
IsNumericWhether scalar is numeric: a decimal digit, a letterlike number, or another number form.
ScriptOfThe script scalar belongs to.
ScriptCountHow many scripts there are, Unknown among them.

Constants

NameSummary
SimpleUpperPairsSimple uppercase pairs: code point, its uppercase.
SimpleLowerPairsSimple lowercase pairs: code point, its lowercase.
SimpleTitlePairsSimple titlecase pairs, for the points whose titlecase differs from their uppercase.
CaseOrbitPairsCase orbits the simple mappings do not pair: code point, the next point that folds to the same point, the largest followed by the smallest.
FullFoldIndexFull case folding index: code point, offset, length.
FullFoldElementsFull case folding elements, indexed by FullFoldIndex.
FullUpperIndexUnconditional full uppercase index: code point, offset, length.
FullUpperElementsUnconditional full uppercase elements.
FullLowerIndexUnconditional full lowercase index: code point, offset, length.
FullLowerElementsUnconditional full lowercase elements.
NormalizationVectorIndexNormalization vector index: five (offset, length) pairs per row, for the columns c1..c5.
NormalizationVectorElementsThe scalar values of every conformance vector, run together end to end.
GraphemeVectorIndexGrapheme vector index: offset, length per row.
GraphemeVectorPointsGrapheme vector code points.
GraphemeVectorBreaksGrapheme vector break masks: bit N set when a boundary precedes point N, the highest bit for the end of the row.
GraphemeBreakRangesGrapheme break class ranges: first, last, class ordinal.
PictographicRangesExtended_Pictographic ranges: first, last.
ConjunctConsonantRangesInCB=Consonant ranges: first, last.
ConjunctLinkerRangesInCB=Linker ranges: first, last.
ConjunctExtendRangesInCB=Extend ranges: first, last.
CanonicalDecompositionIndexCanonical decomposition index: code point, offset, length.
CanonicalDecompositionElementsThe scalar values every canonical decomposition expands to, run together end to end.
CompatibilityDecompositionIndexCompatibility decomposition index: code point, offset, length.
CompatibilityDecompositionElementsThe scalar values every compatibility decomposition expands to, run together end to end.
CompositionTriplesPrimary composite triples: starter, combining, composed.
CategoryRangesGeneral category ranges: first, last, category ordinal.
CombiningClassRangesCanonical combining class ranges: first, last, class.
WhiteSpaceRangesWhite_Space ranges: first, last.
AlphabeticRangesAlphabetic ranges: first, last.
NumericRangesNumeric ranges — the Nd, Nl and No categories: first, last.
ScriptRangesScript ranges: first, last, script number.
ScriptNameIndexScript names: offset into ScriptNameBytes and length, by script number.
ScriptNameBytesThe bytes of the scripts' long names, such as Latin or Old_Italic, all ASCII.
UnknownScriptThe script number of Unknown, the script of a point in no range.
HangulBaseThe first Hangul syllable, LV and LVT composition's base.