Created
August 30, 2016 09:58
-
-
Save anonymous/ab86c64dc651542a7d53ce0dd5c607a9 to your computer and use it in GitHub Desktop.
Shared via Rust Playground
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn title_case(s: &str) -> String { | |
let mut c = s.chars(); | |
match c.next() { | |
None => String::new(), | |
Some(f) => f.to_uppercase().chain(c.flat_map(|t| t.to_lowercase())).collect(), | |
} | |
} | |
fn main() { | |
let s = "foo-bar_baz-QUAX"; | |
let us = s.split('-').map(|v| title_case(v)).collect::<Vec<_>>().join("-"); | |
println!("{}", us); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment