diff options
author | Joris | 2021-01-03 13:40:40 +0100 |
---|---|---|
committer | Joris | 2021-01-03 13:54:20 +0100 |
commit | 11052951b74b9ad4b6a9412ae490086235f9154b (patch) | |
tree | 64526ac926c1bf470ea113f6cac8a33158684e8d /src/utils | |
parent | 371449b0e312a03162b78797b83dee9d81706669 (diff) |
Rewrite in Rust
Diffstat (limited to 'src/utils')
-rw-r--r-- | src/utils/mod.rs | 1 | ||||
-rw-r--r-- | src/utils/text.rs | 19 |
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, + } +} |