blob: dcd4615492906716b53ef12fd5535e10dcc73e53 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
fn to_acronym(word: &str) -> Option<String> {
if word.chars().all(|c| c.is_uppercase() || !c.is_alphabetic())
|| word.chars().all(|c| c.is_lowercase() || !c.is_alphabetic())
{
word.chars()
.find(|c| c.is_alphabetic())
.map(|c| c.to_uppercase().to_string())
} else {
Some(word.chars().filter(|c| c.is_uppercase()).collect())
}
}
pub fn abbreviate(phrase: &str) -> String {
phrase
.split(|c| " -:,".contains(c)) // Split into words
.filter(|s| !s.is_empty())
.flat_map(to_acronym)
.collect()
}
|