From b044dddbed74ac9de900847514691e156c599e92 Mon Sep 17 00:00:00 2001 From: Matthieu Bessat Date: Sun, 21 Jan 2024 23:45:06 +0100 Subject: [PATCH] fix(normalize): first name --- src/test_utils.rs | 6 ++++++ src/utils.rs | 4 +++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/test_utils.rs b/src/test_utils.rs index 5121b04..3526b49 100644 --- a/src/test_utils.rs +++ b/src/test_utils.rs @@ -9,6 +9,12 @@ fn test_normalize_str() { #[test] fn test_normalize_first_name() { + let out = normalize_first_name("jpp jpp".to_string()); + assert_eq!(out, "Jpp-Jpp"); + + let out = normalize_first_name("jean pierre".to_string()); + assert_eq!(out, "Jean-Pierre"); + let out = normalize_first_name("JEAN-PIERRE".to_string()); assert_eq!(out, "Jean-Pierre"); diff --git a/src/utils.rs b/src/utils.rs index 49bfe68..9651adc 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -70,10 +70,12 @@ pub fn capitalize(s: &str) -> String { } } +/// normalisation d'un prénom pub fn normalize_first_name(subject: String) -> String { subject + .trim() .to_lowercase() - .replace(' ', "") + .replace(' ', "-") .split('-') .map(capitalize) .collect::>()