Expand description

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

Usage

Add the crate to your Cargo.toml:

[dependencies]
titlecase = "1.0"

Example

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);

Style

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.

Functions

Returns input in title case.