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.0.5.18 tracks/rust/exercises/acronym/example.rs
trackler-2.0.5.17 tracks/rust/exercises/acronym/example.rs
trackler-2.0.5.16 tracks/rust/exercises/acronym/example.rs
trackler-2.0.5.15 tracks/rust/exercises/acronym/example.rs
trackler-2.0.5.14 tracks/rust/exercises/acronym/example.rs
trackler-2.0.5.13 tracks/rust/exercises/acronym/example.rs
trackler-2.0.5.12 tracks/rust/exercises/acronym/example.rs
trackler-2.0.5.11 tracks/rust/exercises/acronym/example.rs
trackler-2.0.5.10 tracks/rust/exercises/acronym/example.rs
trackler-2.0.5.9 tracks/rust/exercises/acronym/example.rs
trackler-2.0.5.8 tracks/rust/exercises/acronym/example.rs
trackler-2.0.5.7 tracks/rust/exercises/acronym/example.rs
trackler-2.0.5.6 tracks/rust/exercises/acronym/example.rs
trackler-2.0.5.5 tracks/rust/exercises/acronym/example.rs
trackler-2.0.5.4 tracks/rust/exercises/acronym/example.rs
trackler-2.0.5.3 tracks/rust/exercises/acronym/example.rs
trackler-2.0.5.2 tracks/rust/exercises/acronym/example.rs
trackler-2.0.5.1 tracks/rust/exercises/acronym/example.rs
trackler-2.0.5.0 tracks/rust/exercises/acronym/example.rs
trackler-2.0.4.0 tracks/rust/exercises/acronym/example.rs