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

Version Path
trackler-2.2.1.179 tracks/rust/exercises/acronym/example.rs
trackler-2.2.1.178 tracks/rust/exercises/acronym/example.rs
trackler-2.2.1.177 tracks/rust/exercises/acronym/example.rs
trackler-2.2.1.176 tracks/rust/exercises/acronym/example.rs
trackler-2.2.1.175 tracks/rust/exercises/acronym/example.rs
trackler-2.2.1.174 tracks/rust/exercises/acronym/example.rs
trackler-2.2.1.173 tracks/rust/exercises/acronym/example.rs
trackler-2.2.1.172 tracks/rust/exercises/acronym/example.rs
trackler-2.2.1.171 tracks/rust/exercises/acronym/example.rs
trackler-2.2.1.170 tracks/rust/exercises/acronym/example.rs
trackler-2.2.1.169 tracks/rust/exercises/acronym/example.rs
trackler-2.2.1.167 tracks/rust/exercises/acronym/example.rs
trackler-2.2.1.166 tracks/rust/exercises/acronym/example.rs
trackler-2.2.1.165 tracks/rust/exercises/acronym/example.rs
trackler-2.2.1.164 tracks/rust/exercises/acronym/example.rs
trackler-2.2.1.163 tracks/rust/exercises/acronym/example.rs
trackler-2.2.1.162 tracks/rust/exercises/acronym/example.rs
trackler-2.2.1.161 tracks/rust/exercises/acronym/example.rs
trackler-2.2.1.160 tracks/rust/exercises/acronym/example.rs
trackler-2.2.1.159 tracks/rust/exercises/acronym/example.rs