Skip to content

remove_diacritics

Removes diacritical marks (accents) from s, e.g. "café" → "cafe".

Works by Unicode-decomposing each character into its base letter plus combining marks ('é' → 'e' followed by a combining acute accent), then dropping the marks. Needs the string-diacritics feature (not string alone, and not in default): full Unicode normalization needs a real decomposition table, unlike the rest of this module, which is dependency-free.

use helpers4::string::remove_diacritics;

Cargo feature string-diacritics (opt-in): it enables string and adds the unicode-normalization dependency. On top of the default features:

cargo add helpers4 --features string-diacritics

or with only this module:

[dependencies]
helpers4 = { version = "0.0.7", default-features = false, features = ["string-diacritics"] }
pub fn remove_diacritics(s: &str) -> String
ParameterTypeDescription
s&strThe text to strip diacritics from.

String — s with diacritics removed; unchanged if it has none.

use helpers4::string::remove_diacritics;

assert_eq!(remove_diacritics("café"), "cafe");
assert_eq!(remove_diacritics("naïve"), "naive");
assert_eq!(remove_diacritics("ÉCOLE"), "ECOLE");
assert_eq!(remove_diacritics("hello"), "hello");

src/string/remove_diacritics.rs