aboutsummaryrefslogtreecommitdiff
path: root/src/utils
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/mod.rs1
-rw-r--r--src/utils/text.rs19
2 files changed, 20 insertions, 0 deletions
diff --git a/src/utils/mod.rs b/src/utils/mod.rs
new file mode 100644
index 0000000..481c63a
--- /dev/null
+++ b/src/utils/mod.rs
@@ -0,0 +1 @@
+pub mod text;
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,
+ }
+}