From 11052951b74b9ad4b6a9412ae490086235f9154b Mon Sep 17 00:00:00 2001 From: Joris Date: Sun, 3 Jan 2021 13:40:40 +0100 Subject: Rewrite in Rust --- src/utils/mod.rs | 1 + src/utils/text.rs | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 src/utils/mod.rs create mode 100644 src/utils/text.rs (limited to 'src/utils') 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, + } +} -- cgit v1.2.3