diff --git a/rslib/src/typeanswer.rs b/rslib/src/typeanswer.rs index b5abed6de..5356a89a9 100644 --- a/rslib/src/typeanswer.rs +++ b/rslib/src/typeanswer.rs @@ -7,6 +7,8 @@ use std::sync::LazyLock; use difflib::sequencematcher::SequenceMatcher; use regex::Regex; use unic_ucd_category::GeneralCategory; +use unicode_normalization::char::is_combining_mark; +use unicode_normalization::UnicodeNormalization; use crate::card_rendering::strip_av_tags; use crate::text::normalize_to_nfc; @@ -195,18 +197,12 @@ impl DiffTrait for DiffNonCombining { fn new(expected: &str, typed: &str) -> Self { // filter out combining elements - let mut typed_stripped: Vec = Vec::new(); + let typed_stripped: Vec = typed.nfkd().filter(|&c| !is_combining_mark(c)).collect(); let mut expected_stripped: Vec = Vec::new(); // also tokenize into "char+combining" for final rendering let mut expected_split: Vec = Vec::new(); - for c in normalize(typed) { - if !unicode_normalization::char::is_combining_mark(c) { - typed_stripped.push(c); - } - } - - for c in normalize(expected) { + for c in expected.nfkd() { if unicode_normalization::char::is_combining_mark(c) { if let Some(last) = expected_split.last_mut() { last.push(c); @@ -423,5 +419,9 @@ mod test { compare_answer("חוֹף", "חופ", false), "חופ

חוֹף
" ); + assert_eq!( + compare_answer("ば", "は", false), + "" + ); } }