fix(normalize): first name

This commit is contained in:
Matthieu Bessat 2024-01-21 23:45:06 +01:00
parent aa4ea8cc4e
commit b044dddbed
2 changed files with 9 additions and 1 deletions

View file

@ -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");

View file

@ -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::<Vec<String>>()