[][src]Crate titlecase

titlecase capitlizes English text according to a style defined by John Gruber for post titles on his website Daring Fireball.


Add the crate to your Cargo.toml:

titlecase = "1.0"


use titlecase::titlecase;

let text = "a sample title to capitalize: an example";
let capitalized_text =  "A Sample Title to Capitalize: An Example".to_owned();

assert_eq!(titlecase(text), capitalized_text);


Instead of simply capitalizing each word it does the following (amongst other things):

  • Lower case small words like an, of, or in.
  • Don't capitalize words like iPhone.
  • Don't interfere with file paths, URLs, domains, and email addresses.
  • Always capitalize the first and last words, even if they are small words or surrounded by quotes.
  • Don't interfere with terms like "Q&A", or "AT&T".
  • Capitalize small words after a colon.



Returns input in title case.