A Title-Casing Utility that Correctly Lowercases Certain Words
So I decided to polish the titlecasing utility I wrote and open-source it. Since it’s ideal for being incorporated into a much larger program I released it into the public domain using The Unlicense. The code for titlecase.py is available on my github, clone as you please.
There’s no universally agreed-upon ruleset for what words to lowercase when putting a string in title case, but the ruleset from the AP Stylebook wasn’t too hard to adapt. The program applies these rules:
Any single-word article, conjunction, or preposition that's less than 4 characters is lowercased.
Any multi-word conjunction or preposition that's comprised of words all less than 4 characters is lowercased.
The first and last words in the title are capitalized, even if they're an article, conjunction, or preposition, or part of one.
A period-delimited acronym is uppercased.
All other words are capitalized.
23 October 2023