Skip to main content

is_normalized

Function is_normalized 

Source
pub fn is_normalized(s: &str, form: Form) -> bool
Available on crate feature alloc only.
Expand description

Returns true if s is already in normalization form form.

The check begins with the allocation-free Unicode quick-check. Most inputs are decided there; only genuinely ambiguous input triggers a full normalization to resolve, and even then no String is allocated — the normalized scalars are compared against s directly.

§Examples

use unicode_lang::{is_normalized, Form};

assert!(is_normalized("é", Form::Nfc));            // precomposed: already NFC
assert!(!is_normalized("e\u{0301}", Form::Nfc));   // decomposed: not NFC
assert!(is_normalized("e\u{0301}", Form::Nfd));    // ...but it is NFD

assert!(is_normalized("ascii only", Form::Nfkc));
assert!(!is_normalized("fi", Form::Nfkc));          // ligature folds under NFKC