From 1fb5e99efc00b66be23579a36fc397fef1f22b6b Mon Sep 17 00:00:00 2001 From: "a.r" <887320+twwn@users.noreply.github.com> Date: Sat, 14 Dec 2024 11:53:48 +0100 Subject: [PATCH] typeanswer: [type:nc] - use nfkd again (#3627) --- rslib/src/typeanswer.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) 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), + "" + ); } }