mirror of
https://github.com/ankitects/anki.git
synced 2025-09-21 23:42:23 -04:00
nfc helper
This commit is contained in:
parent
933b7a9a34
commit
f7c26724f3
1 changed files with 10 additions and 0 deletions
|
@ -6,6 +6,7 @@ use lazy_static::lazy_static;
|
||||||
use regex::{Captures, Regex};
|
use regex::{Captures, Regex};
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
use std::ptr;
|
use std::ptr;
|
||||||
|
use unicode_normalization::{is_nfc, UnicodeNormalization};
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq)]
|
||||||
pub enum AVTag {
|
pub enum AVTag {
|
||||||
|
@ -156,6 +157,15 @@ pub(crate) fn contains_latex(text: &str) -> bool {
|
||||||
LATEX.is_match(text)
|
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)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use crate::text::{
|
use crate::text::{
|
||||||
|
|
Loading…
Reference in a new issue