14 releases (stable)

2.0.0-beta2 Feb 26, 2025
2.0.0-beta1 Nov 23, 2024
1.5.0 May 28, 2024
1.4.1 Jan 23, 2024
0.0.1 Apr 29, 2021

#13 in Internationalization (i18n)

Download history 906807/week @ 2024-11-21 970820/week @ 2024-11-28 1085023/week @ 2024-12-05 1132919/week @ 2024-12-12 847644/week @ 2024-12-19 697599/week @ 2024-12-26 1103521/week @ 2025-01-02 1410724/week @ 2025-01-09 1421159/week @ 2025-01-16 1422999/week @ 2025-01-23 1565545/week @ 2025-01-30 1655218/week @ 2025-02-06 1661881/week @ 2025-02-13 2254833/week @ 2025-02-20 2323817/week @ 2025-02-27 2133143/week @ 2025-03-06

8,659,532 downloads per month
Used in 30,793 crates (14 directly)

Unicode-3.0

1.5MB
20K SLoC

icu_normalizer crates.io

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 via the icu_harfbuzz crate.

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("ä"));

More Information

For more information on development, authorship, contributing etc. please visit ICU4X home page.

Dependencies

~1.1–1.8MB
~35K SLoC