You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to create a custom word autocompletion for EntryCompletion with set_match_func().
User must be able to print letters without diacritic symbols and see choices that content words with diacritic symbols also.
For example, an user searching through French words and prints "cru" the choices must be "cru" and "crû".
I've created a function for set_match_func() but it doesn't work as expected diacritic symbols still must be printed.
I don't understand what's wrong with it.
fn custom_entry_completion(store: >k::EntryCompletion, text: &str, ti: >k::TreeIter) -> bool {
let tree_model = store.model().expect("Can't get ListStore model.");
let text_column = store.text_column();
let ti_text_value = tree_model.get_value(ti, text_column);
if ti_text_value.is::<String>() {
let value = ti_text_value.get::<String>().expect("Can't get String value.");
let value_clean = diacritic_letter_check(&value);
let text_clean = diacritic_letter_check(&text.to_string());
//println!("{:?} // {:?}", text_clean, value_clean);
if value_clean.starts_with(&text_clean){
//println!("True Text {:?} // Value {:?}", text_clean, value_clean);
return true;
}
return false;
}
false
}
fn diacritic_letter_check(value: &String) -> String{
let diacritic_letters =
"ŠŒŽšœžŸ¥µÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØ\
ÙÚÛÜÝßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýÿ"
.graphemes(true).collect::<Vec<&str>>();
let not_diacritic_letters = gtk::StringList::new(&["S", "OE", "Z", "s", "oe", "z", "Y",
"Y", "u", "A", "A", "A", "A", "A", "A", "AE", "C", "E", "E", "E", "E", "I", "I", "I", "I",
"D", "N", "O", "O", "O", "O", "O", "O", "U", "U", "U", "U", "Y", "s", "a", "a", "a",
"a", "a", "a", "ae", "c", "e", "e", "e", "e", "i", "i", "i", "i", "o", "n", "o", "o", "o",
"o", "o", "o", "u", "u", "u", "u", "y", "y"]);
let value_alph = value.replace(|c: char| !c.is_alphabetic(), "").to_lowercase();
let mut value_clean = "".to_string();
for letter in value_alph.graphemes(true).collect::<Vec<&str>>(){
let diacritic_index = diacritic_letters.iter().position(|n| n == &letter);
if diacritic_index.is_none(){
value_clean.push_str(letter);
}
else{
let index: u32 = diacritic_index.expect("Can't get diacritic index.")
.try_into().expect("Can't convert usize to u32.");
let not_diacritic_letter = not_diacritic_letters
.string(index)
.expect("Can't get GString.");
value_clean.push_str(¬_diacritic_letter);
}
}
value_clean
}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I'm trying to create a custom word autocompletion for EntryCompletion with set_match_func().
User must be able to print letters without diacritic symbols and see choices that content words with diacritic symbols also.
For example, an user searching through French words and prints "cru" the choices must be "cru" and "crû".
I've created a function for set_match_func() but it doesn't work as expected diacritic symbols still must be printed.
I don't understand what's wrong with it.
Beta Was this translation helpful? Give feedback.
All reactions