Skip to content

Commit

Permalink
Handle initials correctly (#150)
Browse files Browse the repository at this point in the history
  • Loading branch information
razvanazamfirei committed Apr 8, 2024
1 parent 3315538 commit 5aec683
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/types/persons.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,11 @@ impl Person {
}

collect = true;
buf.write_char(if with_hyphen { c } else { ' ' })?;
if with_hyphen && c == '-' {
buf.write_char(c)?;
} else if delimiter.is_some() {
buf.write_char(' ')?;
}
}
continue;
}
Expand Down Expand Up @@ -533,6 +537,11 @@ mod tests {
p.initials(&mut s, Some("."), true).unwrap();
assert_eq!("C. D.", s);

let mut s = String::new();
let p = Person::from_strings(vec!["Dissmer", "Courtney Deliah"]).unwrap();
p.initials(&mut s, None, true).unwrap();
assert_eq!("CD", s);

let mut s = String::new();
let p = Person::from_strings(vec!["Günther", "Hans-Joseph"]).unwrap();
p.initials(&mut s, None, true).unwrap();
Expand Down

0 comments on commit 5aec683

Please sign in to comment.