mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 14:02:21 -04:00
typeanswer: 'simplify' by removing normalize_typed (requiring a bool parameter)
I'd prefer to keep this extra method.
This commit is contained in:
parent
2106c4306f
commit
df2dd3394e
1 changed files with 15 additions and 17 deletions
|
@ -50,7 +50,6 @@ trait DiffTrait {
|
|||
fn get_expected_original(&self) -> Cow<str>;
|
||||
|
||||
fn new(expected: &str, typed: &str) -> Self;
|
||||
fn normalize_typed(typed: &str) -> Vec<char>;
|
||||
|
||||
// Entry Point
|
||||
fn to_html(&self) -> String {
|
||||
|
@ -108,8 +107,17 @@ trait DiffTrait {
|
|||
}
|
||||
|
||||
// Utility Functions
|
||||
fn normalize(string: &str) -> Vec<char> {
|
||||
normalize_to_nfkd(string).chars().collect()
|
||||
fn normalize(string: &str, retain_combining: bool) -> Vec<char> {
|
||||
let binding = normalize_to_nfkd(string);
|
||||
let chars = binding.chars();
|
||||
|
||||
if retain_combining {
|
||||
chars.collect()
|
||||
} else {
|
||||
chars
|
||||
.filter(|c| !unicode_normalization::char::is_combining_mark(*c))
|
||||
.collect()
|
||||
}
|
||||
}
|
||||
|
||||
fn slice(chars: &[char], start: usize, end: usize) -> String {
|
||||
|
@ -166,13 +174,10 @@ impl DiffTrait for Diff {
|
|||
|
||||
fn new(expected: &str, typed: &str) -> Self {
|
||||
Self {
|
||||
typed: Self::normalize_typed(typed),
|
||||
expected: normalize(&prepare_expected(expected)),
|
||||
typed: normalize(typed, true),
|
||||
expected: normalize(&prepare_expected(expected), true),
|
||||
}
|
||||
}
|
||||
fn normalize_typed(typed: &str) -> Vec<char> {
|
||||
normalize(typed)
|
||||
}
|
||||
|
||||
fn render_expected_tokens(&self, tokens: &[DiffToken]) -> String {
|
||||
render_tokens(tokens)
|
||||
|
@ -202,7 +207,7 @@ impl DiffTrait for DiffNonCombining {
|
|||
let mut expected_stripped = String::new();
|
||||
// tokenized into "char+combining" for final rendering
|
||||
let mut expected_split: Vec<String> = Vec::new();
|
||||
for c in normalize(&prepare_expected(expected)) {
|
||||
for c in normalize(&prepare_expected(expected), true) {
|
||||
if unicode_normalization::char::is_combining_mark(c) {
|
||||
if let Some(last) = expected_split.last_mut() {
|
||||
last.push(c);
|
||||
|
@ -215,7 +220,7 @@ impl DiffTrait for DiffNonCombining {
|
|||
|
||||
Self {
|
||||
base: Diff {
|
||||
typed: Self::normalize_typed(typed),
|
||||
typed: normalize(typed, false),
|
||||
expected: expected_stripped.chars().collect(),
|
||||
},
|
||||
expected_split,
|
||||
|
@ -223,13 +228,6 @@ impl DiffTrait for DiffNonCombining {
|
|||
}
|
||||
}
|
||||
|
||||
fn normalize_typed(typed: &str) -> Vec<char> {
|
||||
normalize_to_nfkd(typed)
|
||||
.chars()
|
||||
.filter(|c| !unicode_normalization::char::is_combining_mark(*c))
|
||||
.collect()
|
||||
}
|
||||
|
||||
// Since the combining characters are still required learning content, use
|
||||
// expected_split to show them directly in the "expected" line, rather than
|
||||
// having to otherwise e.g. include their field twice in the note template.
|
||||
|
|
Loading…
Reference in a new issue