diff --git a/rslib/src/text.rs b/rslib/src/text.rs index f6be8a106..a612632f2 100644 --- a/rslib/src/text.rs +++ b/rslib/src/text.rs @@ -6,6 +6,7 @@ use lazy_static::lazy_static; use regex::{Captures, Regex}; use std::borrow::Cow; use std::ptr; +use unicode_normalization::{is_nfc, UnicodeNormalization}; #[derive(Debug, PartialEq)] pub enum AVTag { @@ -156,6 +157,15 @@ pub(crate) fn contains_latex(text: &str) -> bool { LATEX.is_match(text) } +#[allow(dead_code)] +pub(crate) fn normalize_to_nfc(s: &str) -> Cow { + if !is_nfc(s) { + s.chars().nfc().collect::().into() + } else { + s.into() + } +} + #[cfg(test)] mod test { use crate::text::{