Wado

core:icu

Unicode character properties, locale-aware collation and case mapping, and grapheme segmentation, from the ICU4X component bundled with the toolchain.

A property value is an enum case of its property (Script::Latin), and a program carries the data of the properties it names and no others, except that naming one binary property carries all of them. A name read at run time parses through FromStr or LenientFromStr, and one this build does not answer is refused, never approximated: Block, Decomposition_Type and the contributory Other_* are withheld.

Every locale-aware operation takes its Locale explicitly; none falls back to an implicit one.

Synopsis

assert contains(BinaryProperty::Uppercase, 'À');
assert contains(Script::Hiragana, 'あ');
assert ranges(GeneralCategoryGroup::Letter)[0] == [65, 90];
assert Property::from_str_lenient("sc=hiragana") == Result::Ok(Property::Script(Script::Hiragana));

let tr = Locale::from("tr");
assert tr.uppercase("istanbul") == "İSTANBUL";

let swedish = Collator::new(&Locale::from("sv"));
let mut words: List<String> = ["ö", "z", "a"];
words.sort_by(|a, b| swedish.compare(*a, *b));
assert words == ["a", "z", "ö"];

assert grapheme_count("🇯🇵") == 1;

Functions

pub fn ranges<P: CodePointSet>(property: P) -> List<[u32, u32]>

The inclusive code point ranges of a property or property value, lowest first: ranges(BinaryProperty::WhiteSpace), ranges(GeneralCategoryGroup::Letter).

pub fn contains<P: CodePointSet>(property: P, ch: char) -> bool

Whether ch has the property or property value, without building the ranges.

pub fn graphemes(text: String) -> Graphemes

The extended grapheme clusters of text (UAX #29), in order: what a reader counts as one character each.

pub fn grapheme_count(text: String) -> i32

How many extended grapheme clusters text holds.

Traits

pub trait CodePointSet with ()

A property, or a value of one: the set of code points that have it.

fn ranges(&self) -> List<[u32, u32]>

The inclusive code point ranges of the set, lowest first.

fn contains(&self, ch: char) -> bool

Whether ch is in the set, without building the ranges.

Structs

pub struct Locale

A locale: the language, script and region subtags of a BCP 47 tag, which are what select ICU4X's locale data. Variants and extensions are dropped. Each subtag is held as its ASCII bytes in canonical case, so a locale is parsed once and crosses to ICU4X as three numbers.

Fields are private.

pub fn is_well_formed<S: AsStrSlice>(tag: S) -> bool

Whether tag is a well-formed Unicode BCP 47 locale identifier (UTS #35), with - between subtags. A language subtag of 5 to 8 letters is refused: BCP 47 reserves the length, and no language has one.

pub fn uppercase(&self, text: String) -> String

Full uppercase mapping of text.

pub fn lowercase(&self, text: String) -> String

Full lowercase mapping of text.

pub fn fold(&self, text: String) -> String

Full case folding of text, for caseless matching. tr and az fold I to dotless ı and İ to i, as Turkic does.

pub fn eq_ignore_case(&self, left: String, right: String) -> bool

Whether left and right fold to the same text.

impl TryFrom<String> for Locale

fn try_from(tag: String) -> Result<Locale, LocaleError>

impl From<String> for Locale

fn from(tag: String) -> Locale

The locale of a tag known to be well-formed; Locale::try_from answers for one that may not be.

impl Display for Locale

fn fmt(&self, f: &mut Formatter)

pub struct LocaleError

Why a locale was refused: the tag is not well-formed BCP 47.

Fields are private.

impl Display for LocaleError

fn fmt(&self, f: &mut Formatter)

pub affine struct Collator

Compares strings the way a locale sorts them.

Fields are private.

pub fn new(locale: &Locale) -> Collator

A collator for locale. A locale CLDR tailors nothing for sorts as its fallback does, ending at the root collation.

pub fn compare(&self, left: String, right: String) -> Ordering

How left sorts against right.

pub struct Graphemes

The iterator [graphemes] returns.

Fields are private.

impl Iterator for Graphemes

fn next(&mut self) -> Option<StrSlice>

pub struct PropertyNameError

Why a name was refused: it names nothing this build answers. That is never answered with an approximate set instead, since a caller complementing one would admit real members of the property rather than miss some.

Fields are private.

impl Display for PropertyNameError

fn fmt(&self, f: &mut Formatter)

Variants

pub variant Property

A property, or a value of one, named at run time: what a \p{...} in a grammar names. It parses from a binary property's name (White_Space) or from property=value (sc=Latin), as FromStr or LenientFromStr match names.

BinaryProperty(BinaryProperty)

GeneralCategoryGroup(GeneralCategoryGroup)

BidiClass(BidiClass)

CanonicalCombiningClass(CanonicalCombiningClass)

EastAsianWidth(EastAsianWidth)

GraphemeClusterBreak(GraphemeClusterBreak)

HangulSyllableType(HangulSyllableType)

IndicConjunctBreak(IndicConjunctBreak)

IndicSyllabicCategory(IndicSyllabicCategory)

JoiningGroup(JoiningGroup)

JoiningType(JoiningType)

LineBreak(LineBreak)

NumericType(NumericType)

Script(Script)

SentenceBreak(SentenceBreak)

VerticalOrientation(VerticalOrientation)

WordBreak(WordBreak)

Enums

pub enum BinaryProperty

The binary properties, each the set of code points that have it.

Alnum

Alphabetic

AsciiHexDigit

BidiControl

BidiMirrored

Blank

CaseIgnorable

Cased

ChangesWhenCasefolded

ChangesWhenCasemapped

ChangesWhenLowercased

ChangesWhenNfkcCasefolded

ChangesWhenTitlecased

ChangesWhenUppercased

Dash

DefaultIgnorableCodePoint

Deprecated

Diacritic

Emoji

EmojiComponent

EmojiModifier

EmojiModifierBase

EmojiPresentation

ExtendedPictographic

Extender

FullCompositionExclusion

Graph

GraphemeBase

GraphemeExtend

HexDigit

Hyphen

IdCompatMathContinue

IdCompatMathStart

IdContinue

IdStart

Ideographic

IdsBinaryOperator

IdsTrinaryOperator

IdsUnaryOperator

JoinControl

LogicalOrderException

Lowercase

Math

ModifierCombiningMark

NoncharacterCodePoint

PatternSyntax

PatternWhiteSpace

PrependedConcatenationMark

Print

QuotationMark

Radical

RegionalIndicator

SentenceTerminal

SoftDotted

TerminalPunctuation

UnifiedIdeograph

Uppercase

VariationSelector

WhiteSpace

Xdigit

XidContinue

XidStart

pub enum GeneralCategoryGroup

The values of General_Category (gc): the categories, and the groups UAX #44 names over them (Letter is L).

Unassigned

UppercaseLetter

LowercaseLetter

TitlecaseLetter

ModifierLetter

OtherLetter

NonspacingMark

EnclosingMark

SpacingMark

DecimalNumber

LetterNumber

OtherNumber

SpaceSeparator

LineSeparator

ParagraphSeparator

Control

Format

PrivateUse

Surrogate

DashPunctuation

OpenPunctuation

ClosePunctuation

ConnectorPunctuation

OtherPunctuation

MathSymbol

CurrencySymbol

ModifierSymbol

OtherSymbol

InitialPunctuation

FinalPunctuation

CasedLetter

Letter

Mark

Number

Punctuation

Symbol

Separator

Other

pub enum BidiClass

The values of Bidi_Class (bc).

LeftToRight

RightToLeft

EuropeanNumber

EuropeanSeparator

EuropeanTerminator

ArabicNumber

CommonSeparator

ParagraphSeparator

SegmentSeparator

WhiteSpace

OtherNeutral

LeftToRightEmbedding

LeftToRightOverride

ArabicLetter

RightToLeftEmbedding

RightToLeftOverride

PopDirectionalFormat

NonspacingMark

BoundaryNeutral

FirstStrongIsolate

LeftToRightIsolate

RightToLeftIsolate

PopDirectionalIsolate

pub enum CanonicalCombiningClass

The values of Canonical_Combining_Class (ccc).

NotReordered

Overlay

HanReading

Nukta

KanaVoicing

Virama

Ccc10

Ccc11

Ccc12

Ccc13

Ccc14

Ccc15

Ccc16

Ccc17

Ccc18

Ccc19

Ccc20

Ccc21

Ccc22

Ccc23

Ccc24

Ccc25

Ccc26

Ccc27

Ccc28

Ccc29

Ccc30

Ccc31

Ccc32

Ccc33

Ccc34

Ccc35

Ccc36

Ccc84

Ccc91

Ccc103

Ccc107

Ccc118

Ccc122

Ccc129

Ccc130

Ccc132

Ccc133

AttachedBelowLeft

AttachedBelow

AttachedAbove

AttachedAboveRight

BelowLeft

Below

BelowRight

Left

AboveLeft

Above

AboveRight

DoubleBelow

DoubleAbove

IotaSubscript

pub enum EastAsianWidth

The values of East_Asian_Width (ea).

Neutral

Ambiguous

Halfwidth

Fullwidth

Narrow

Wide

pub enum GraphemeClusterBreak

The values of Grapheme_Cluster_Break (GCB).

Other

Control

Cr

Extend

L

Lf

Lv

Lvt

T

V

SpacingMark

Prepend

RegionalIndicator

EBase

EBaseGaz

EModifier

GlueAfterZwj

Zwj

pub enum HangulSyllableType

The values of Hangul_Syllable_Type (hst).

NotApplicable

LeadingJamo

VowelJamo

TrailingJamo

LvSyllable

LvtSyllable

pub enum IndicConjunctBreak

The values of Indic_Conjunct_Break (InCB).

None

Consonant

Extend

Linker

pub enum IndicSyllabicCategory

The values of Indic_Syllabic_Category (InSC).

Other

Avagraha

Bindu

BrahmiJoiningNumber

CantillationMark

Consonant

ConsonantDead

ConsonantFinal

ConsonantHeadLetter

ConsonantInitialPostfixed

ConsonantKiller

ConsonantMedial

ConsonantPlaceholder

ConsonantPrecedingRepha

ConsonantPrefixed

ConsonantSubjoined

ConsonantSucceedingRepha

ConsonantWithStacker

GeminationMark

InvisibleStacker

Joiner

ModifyingLetter

NonJoiner

Nukta

Number

NumberJoiner

PureKiller

RegisterShifter

SyllableModifier

ToneLetter

ToneMark

Virama

Visarga

Vowel

VowelDependent

VowelIndependent

ReorderingKiller

pub enum JoiningGroup

The values of Joining_Group (jg).

NoJoiningGroup

Ain

Alaph

Alef

Beh

Beth

Dal

DalathRish

E

Feh

FinalSemkath

Gaf

Gamal

Hah

TehMarbutaGoal

He

Heh

HehGoal

Heth

Kaf

Kaph

KnottedHeh

Lam

Lamadh

Meem

Mim

Noon

Nun

Pe

Qaf

Qaph

Reh

ReversedPe

Sad

Sadhe

Seen

Semkath

Shin

SwashKaf

SyriacWaw

Tah

Taw

TehMarbuta

Teth

Waw

Yeh

YehBarree

YehWithTail

Yudh

YudhHe

Zain

Fe

Khaph

Zhain

BurushaskiYehBarree

FarsiYeh

Nya

RohingyaYeh

ManichaeanAleph

ManichaeanAyin

ManichaeanBeth

ManichaeanDaleth

ManichaeanDhamedh

ManichaeanFive

ManichaeanGimel

ManichaeanHeth

ManichaeanHundred

ManichaeanKaph

ManichaeanLamedh

ManichaeanMem

ManichaeanNun

ManichaeanOne

ManichaeanPe

ManichaeanQoph

ManichaeanResh

ManichaeanSadhe

ManichaeanSamekh

ManichaeanTaw

ManichaeanTen

ManichaeanTeth

ManichaeanThamedh

ManichaeanTwenty

ManichaeanWaw

ManichaeanYodh

ManichaeanZayin

StraightWaw

AfricanFeh

AfricanNoon

AfricanQaf

MalayalamBha

MalayalamJa

MalayalamLla

MalayalamLlla

MalayalamNga

MalayalamNna

MalayalamNnna

MalayalamNya

MalayalamRa

MalayalamSsa

MalayalamTta

HanifiRohingyaKinnaYa

HanifiRohingyaPa

ThinYeh

VerticalTail

KashmiriYeh

ThinNoon

pub enum JoiningType

The values of Joining_Type (jt).

NonJoining

JoinCausing

DualJoining

LeftJoining

RightJoining

Transparent

pub enum LineBreak

The values of Line_Break (lb).

Unknown

Ambiguous

Alphabetic

BreakBoth

BreakAfter

BreakBefore

MandatoryBreak

ContingentBreak

ClosePunctuation

CombiningMark

CarriageReturn

Exclamation

Glue

Hyphen

Ideographic

Inseparable

InfixNumeric

LineFeed

Nonstarter

Numeric

OpenPunctuation

PostfixNumeric

PrefixNumeric

Quotation

ComplexContext

Surrogate

Space

BreakSymbols

ZwSpace

NextLine

WordJoiner

H2

H3

Jl

Jt

Jv

CloseParenthesis

ConditionalJapaneseStarter

HebrewLetter

RegionalIndicator

EBase

EModifier

Zwj

Aksara

AksaraPrebase

AksaraStart

ViramaFinal

Virama

UnambiguousHyphen

pub enum NumericType

The values of Numeric_Type (nt).

None

Decimal

Digit

Numeric

pub enum Script

The values of Script (sc).

Common

Inherited

Arabic

Armenian

Bengali

Bopomofo

Cherokee

Coptic

Cyrillic

Deseret

Devanagari

Ethiopic

Georgian

Gothic

Greek

Gujarati

Gurmukhi

Han

Hangul

Hebrew

Hiragana

Kannada

Katakana

Khmer

Lao

Latin

Malayalam

Mongolian

Myanmar

Ogham

OldItalic

Oriya

Runic

Sinhala

Syriac

Tamil

Telugu

Thaana

Thai

Tibetan

CanadianAboriginal

Yi

Tagalog

Hanunoo

Buhid

Tagbanwa

Braille

Cypriot

Limbu

LinearB

Osmanya

Shavian

TaiLe

Ugaritic

KatakanaOrHiragana

Buginese

Glagolitic

Kharoshthi

SylotiNagri

NewTaiLue

Tifinagh

OldPersian

Balinese

Batak

Blis

Brahmi

Cham

Cirt

Cyrs

Egyd

Egyh

EgyptianHieroglyphs

Geok

Hans

Hant

PahawhHmong

OldHungarian

Inds

Javanese

KayahLi

Latf

Latg

Lepcha

LinearA

Mandaic

Maya

MeroiticHieroglyphs

Nko

OldTurkic

OldPermic

PhagsPa

Phoenician

Miao

Roro

Sara

Syre

Syrj

Syrn

Teng

Vai

Visp

Cuneiform

Zxxx

Unknown

Carian

Jpan

TaiTham

Lycian

Lydian

OlChiki

Rejang

Saurashtra

SignWriting

Sundanese

Moon

MeeteiMayek

ImperialAramaic

Avestan

Chakma

Kore

Kaithi

Manichaean

InscriptionalPahlavi

PsalterPahlavi

Phlv

InscriptionalParthian

Samaritan

TaiViet

Zmth

Zsym

Bamum

Lisu

Nkgb

OldSouthArabian

BassaVah

Duployan

Elbasan

Grantha

Kpel

Loma

MendeKikakui

MeroiticCursive

OldNorthArabian

Nabataean

Palmyrene

Khudawadi

WarangCiti

Afak

Jurc

Mro

Nushu

Sharada

SoraSompeng

Takri

Tangut

Wole

AnatolianHieroglyphs

Khojki

Tirhuta

CaucasianAlbanian

Mahajani

Ahom

Hatran

Modi

Multani

PauCinHau

Siddham

Adlam

Bhaiksuki

Marchen

Newa

Osage

Hanb

Jamo

Zsye

MasaramGondi

Soyombo

ZanabazarSquare

Dogra

GunjalaGondi

Makasar

Medefaidrin

HanifiRohingya

Sogdian

OldSogdian

Elymaic

NyiakengPuachueHmong

Nandinagari

Wancho

Chorasmian

DivesAkuru

KhitanSmallScript

Yezidi

CyproMinoan

OldUyghur

Tangsa

Toto

Vithkuqi

Kawi

NagMundari

Aran

Garay

GurungKhema

KiratRai

OlOnal

Sunuwar

Todhri

TuluTigalari

BeriaErfe

Sidetic

TaiYo

TolongSiki

Hntl

pub enum SentenceBreak

The values of Sentence_Break (SB).

Other

ATerm

Close

Format

Lower

Numeric

OLetter

Sep

Sp

STerm

Upper

Cr

Extend

Lf

SContinue

pub enum VerticalOrientation

The values of Vertical_Orientation (vo).

Rotated

TransformedRotated

TransformedUpright

Upright

pub enum WordBreak

The values of Word_Break (WB).

Other

ALetter

Format

Katakana

MidLetter

MidNum

Numeric

ExtendNumLet

Cr

Extend

Lf

MidNumLet

Newline

RegionalIndicator

HebrewLetter

SingleQuote

DoubleQuote

EBase

EBaseGaz

EModifier

GlueAfterZwj

Zwj

WSegSpace