1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
pub fn to_train_case(text: &String) -> String { if text.trim().is_empty() { return text.to_owned(); } let mut chars = text.chars(); let mut new_chars = Vec::new(); let first_char = chars.next().unwrap(); new_chars.push(first_char.to_ascii_uppercase()); while let Some(c) = chars.next() { if c == '-' { if let Some(next) = chars.next() { new_chars.push(c); new_chars.push(next.to_ascii_uppercase()); } } else { new_chars.push(c); } } return new_chars.iter().collect(); }