Sha256: 15e763e92e99a4d3fc2c16b7a77c1032bb633edcf37a7e69fadce278b51e39a2
Contents?: true
Size: 715 Bytes
Versions: 395
Compression:
Stored size: 715 Bytes
Contents
pub fn abbreviate(phrase: &str) -> String { phrase.split(|c: char| c.is_whitespace() || !c.is_alphanumeric()) .flat_map(|word| split_camel(word)) .filter_map(|word| word.chars().next()) .collect::<String>() .to_uppercase() } fn split_camel(phrase: &str) -> Vec<String> { let chars: Vec<char> = phrase.chars().collect(); let mut words: Vec<String> = Vec::new(); let mut word_start: usize = 0; for (i, c) in chars.iter().enumerate() { if i == chars.len() - 1 || c.is_lowercase() && chars[i + 1].is_uppercase() { words.push(chars[word_start..i + 1].iter().cloned().collect()); word_start = i + 1; } } words }
Version data entries
395 entries across 395 versions & 1 rubygems