Expand description
Normalizing text into Unicode Normalization Forms.
This module is published as its own crate (icu_normalizer)
and as part of the icu crate. See the latter for more details on the ICU4X project.
§Functionality
The top level of the crate provides normalization of input into the four normalization forms defined in UAX #15: Unicode Normalization Forms: NFC, NFD, NFKC, and NFKD.
Three kinds of contiguous inputs are supported: known-well-formed UTF-8 (&str), potentially-not-well-formed UTF-8,
and potentially-not-well-formed UTF-16. Additionally, an iterator over char can be wrapped in a normalizing iterator.
The uts46 module provides the combination of mapping and normalization operations for UTS #46: Unicode IDNA
Compatibility Processing. This functionality is not meant to be used by
applications directly. Instead, it is meant as a building block for a full implementation of UTS #46, such as the
idna crate.
The properties module provides the non-recursive canonical decomposition operation on a per char basis and
the canonical compositon operation given two chars. It also provides access to the Canonical Combining Class
property. These operations are primarily meant for HarfBuzz, the types
CanonicalComposition, CanonicalDecomposition,
and CanonicalCombiningClassMap implement the [harfbuzz_traits] if
the harfbuzz_traits Cargo feature is enabled.
Notably, this normalizer does not provide the normalization “quick check” that can result in “maybe” in addition to “yes” and “no”. The normalization checks provided by this crate always give a definitive non-“maybe” answer.
§Examples
let nfc = icu_normalizer::ComposingNormalizerBorrowed::new_nfc();
assert_eq!(nfc.normalize("a\u{0308}"), "ä");
assert!(nfc.is_normalized("ä"));
let nfd = icu_normalizer::DecomposingNormalizerBorrowed::new_nfd();
assert_eq!(nfd.normalize("ä"), "a\u{0308}");
assert!(!nfd.is_normalized("ä"));Modules§
- latin1
- Methods for normalizing Latin1 input into a UTF-16 sink.
- properties
- Access to the Unicode properties or property-based operations that are required for NFC and NFD.
- provider
- 🚧 [Unstable] Data provider struct definitions for this ICU4X component.
- uts46
- Bundles the part of UTS 46 that makes sense to implement as a normalization.
Macros§
Structs§
- Canonical
Combining 🔒Class - This type exists as a shim for icu_properties CanonicalCombiningClass when the crate is disabled It should not be exposed to users.
- Character
AndClass 🔒 - Pack a
charand aCanonicalCombiningClassin 32 bits (the former in the lower 24 bits and the latter in the high 8 bits). The latter can be initialized to 0xFF upon creation, in which case it can be actually set later by callingset_ccc_from_trie_if_not_already_set. This is a micro optimization to avoid the Canonical Combining Class trie lookup when there is only one combining character in a sequence. This type is intentionally non-Copyto get compiler help in making sure that the class is set on the instance on which it is intended to be set and not on a temporary copy. - Character
AndTrie 🔒Value - Struct for holding together a character and the value looked up for it from the NFD trie in a more explicit way than an anonymous pair. Also holds a flag about the supplementary-trie provenance.
- Composing
Normalizer - A normalizer for performing composing normalization.
- Composing
Normalizer Borrowed - Borrowed version of a normalizer for performing composing normalization.
- Composition
- An iterator adaptor that turns an
Iteratorovercharinto a lazily-decomposed and then canonically composedcharsequence. - Composition
Inner 🔒 - Decomposing
Normalizer - A normalizer for performing decomposing normalization.
- Decomposing
Normalizer Borrowed - Borrowed version of a normalizer for performing decomposing normalization.
- Decomposition
- An iterator adaptor that turns an
Iteratorovercharinto a lazily-decomposedcharsequence. - Decomposition
Inner 🔒 - IsNormalized
Sink 🔒Str - IsNormalized
Sink 🔒Utf8 - IsNormalized
Sink 🔒Utf16 - Uax15
Policy 🔒
Enums§
- Canonical
Compositions 🔒Borrowed - Canonical
Compositions 🔒Payload - Canonical
Compositions 🔒Ref - Ignorable
Behavior 🔒 - Treatment of the ignorable marker (0xFFFFFFFF) in data.
Constants§
- BACKWARD_
COMBINING_ 🔒MARKER - Marker that the first character of the decomposition can combine backwards.
- CCC_
ABOVE 🔒 - CCC_
NOT_ 🔒REORDERED - EMPTY_
CHAR 🔒 - EMPTY_
U16 🔒 - FDFA_
MARKER 🔒 - Marker value for U+FDFA in NFKD. (Unified with Hangul syllable marker,
but they differ by
NON_ROUND_TRIP_MARKER.) - HANGUL_
L_ 🔒BASE - Lead jamo base
- HANGUL_
L_ 🔒COUNT - Lead jamo count
- HANGUL_
L_ 🔒TRIE_ VAL_ BASE - Trie value base corresponding for L
- HANGUL_
N_ 🔒COUNT - Vowel jamo count times trail jamo count
- HANGUL_
S_ 🔒BASE - Syllable base
- HANGUL_
S_ 🔒COUNT - Syllable count
- HANGUL_
T_ 🔒BASE - Trail jamo base (deliberately off by one to account for the absence of a trail)
- HANGUL_
T_ 🔒COUNT - Trail jamo count (deliberately off by one to account for the absence of a trail)
- HANGUL_
V_ 🔒BASE - Vowel jamo base
- HANGUL_
V_ 🔒COUNT - Vowel jamo count
- HIGH_
ZEROS_ 🔒MASK - Mask for the bits have to be zero for this to be a BMP singleton decomposition, or value baked into the surrogate range.
- IGNORABLE_
MARKER 🔒 - Marker for UTS 46 ignorables.
- LOW_
ZEROS_ 🔒MASK - Mask for the bits have to be zero for this to be a complex decomposition.
- NON_
ROUND_ 🔒TRIP_ MARKER - Marker that the decomposition does not round trip via NFC.
Statics§
- FDFA_
NFKD 🔒 - The tail (everything after the first character) of the NFKD form U+FDFA as 16-bit units.
Traits§
Functions§
- ccc_
from_ 🔒trie_ value - Extracts a canonical combining class (possibly zero) from a trie value.
- char_
from_ 🔒u16 - Convert a
u16obtained from data provider data tochar. - char_
from_ 🔒u32 - Convert a
u32obtained from data provider data tochar. - cold_
path 🔒 - decomposition_
starts_ 🔒with_ non_ starter - Checks if a trie value signifies a character whose decomposition starts with a non-starter.
- in_
inclusive_ 🔒range - in_
inclusive_ 🔒range16 - likely 🔒
- potential_
passthrough_ 🔒and_ cannot_ combine_ backwards - See trie-value-format.md
- starter_
and_ decomposes_ to_ self_ except_ replacement - See trie-value-format.md
- starter_
and_ 🔒decomposes_ to_ self_ impl - See trie-value-format.md
- trie_
value_ 🔒has_ ccc - Checks if a trie value carries a (non-zero) canonical combining class.
- trie_
value_ 🔒indicates_ non_ decomposing_ non_ starter - Checks if the trie signifies a non-decomposing non-starter.
- trie_
value_ 🔒indicates_ special_ non_ starter_ decomposition - Checks if the trie signifies a special non-starter decomposition.
- unlikely 🔒
- unwrap_
or_ 🔒gigo - If
optisSome, unwrap it. IfNone, panic if debug assertions are enabled and returndefaultif debug assertions are not enabled.