aboutsummaryrefslogtreecommitdiff
path: root/src/utils/text.rs
blob: 8985210797caf63c58775f42d82d41c9f577e305 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
pub fn format_search(str: &str) -> String {
    format!("%{}%", unaccent(&str.to_lowercase()))
}

pub fn unaccent(str: &str) -> String {
    str.chars().map(unaccent_char).collect()
}

pub fn unaccent_char(c: char) -> char {
    match c {
        'à' | 'â' => 'a',
        'ç' => 'c',
        'è' | 'é' | 'ê' | 'ë' => 'e',
        'î' | 'ï' => 'i',
        'ô' => 'o',
        'ù' | 'û' | 'ü' => 'u',
        _ => c,
    }
}