aboutsummaryrefslogtreecommitdiff
path: root/src/utils/text.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils/text.rs')
-rw-r--r--src/utils/text.rs19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/utils/text.rs b/src/utils/text.rs
new file mode 100644
index 0000000..c07ccee
--- /dev/null
+++ b/src/utils/text.rs
@@ -0,0 +1,19 @@
+pub fn format_search(str: &String) -> String {
+ unaccent(&str.to_lowercase())
+}
+
+pub fn unaccent(str: &String) -> String {
+ str.chars().map(unaccent_char).collect()
+}
+
+pub fn unaccent_char(c: char) -> char {
+ match c {
+ 'à' | 'â' => 'a',
+ 'ç' => 'c',
+ 'è' | 'é' | 'ê' | 'ë' => 'e',
+ 'î' | 'ï' => 'i',
+ 'ô' => 'o',
+ 'ù' | 'û' | 'ü' => 'u',
+ _ => c,
+ }
+}