Add the crate to your
[dependencies] 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.