According to this site a general rule recommended by The U.S. Government Printing Office Style Manual is
Capitalize all words in titles of publications and documents, except a, an, the, at, by, for, in, of, on, to, up, and, as, but, or, and nor.
This might not be true as I'm unable to find such a recommendation in the Style Manual, but let's use this rule anyway.
The Challenge
Given an input string consisting of lower case words delimited by spaces, output the capitalization of the string according to the following rules
- The first and last word is capitalized.
- All other words are capitalized, except a, an, the, at, by, for, in, of, on, to, up, and, as, but, or, and nor.
The input string will contain at least one word and each word contains at least one letter and only characters from a
to z
.
This is a code golf challenge, so try to use as few bytes as possible in the language of your choice. You may write a full program or a function to accomplish the task.
Testcases
"the rule of thumb for title capitalization" -> "The Rule of Thumb for Title Capitalization"
"programming puzzles and code golf" -> "Programming Puzzles and Code Golf"
"the many uses of the letter a" -> "The Many Uses of the Letter A"
"title" -> "Title"
"and and and" -> "And and And"
"a an and as at but by for in nor of on or the to up" -> "A an and as at but by for in nor of on or the to Up"
"on computable numbers with an application to the entscheidungsproblem" -> "On Computable Numbers With an Application to the Entscheidungsproblem"