nfc helper

This commit is contained in:
Damien Elmes 2020-02-08 20:56:30 +10:00
parent 933b7a9a34
commit f7c26724f3

View File

@ -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<str> {
if !is_nfc(s) {
s.chars().nfc().collect::<String>().into()
} else {
s.into()
}
}
#[cfg(test)]
mod test {
use crate::text::{