Skip to main content

normalize

Function normalize 

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

Returns s normalized to form.

When s is already in the requested form this returns it unchanged after a fast allocation-free scan (the Unicode quick-check), so passing text that is already normalized — the common case for ASCII and most well-formed input — costs one linear pass and a single allocation for the returned String.

§Examples

use unicode_lang::{normalize, Form};

// Compatibility composition folds a ligature and a fullwidth digit.
assert_eq!(normalize("file", Form::Nfkc), "file");
assert_eq!(normalize("\u{FF11}", Form::Nfkc), "1");

// Canonical decomposition splits a precomposed character and orders marks.
assert_eq!(normalize("ǭ", Form::Nfd), "o\u{0328}\u{0304}");

// ASCII is returned untouched.
assert_eq!(normalize("plain ascii", Form::Nfc), "plain ascii");