Title Case Update

Back in May, I published a Perl script I wrote for properly title-casing text. Its main trick was in being smart about “small words” that should not be capitalized even in title case.

I wrote:

The source code itself is, uh, rather convoluted, to say the least. It’s one of those pieces of code that started small and simple, and grew ugly over time as edge cases were worked around one at a time. I’ve been using this script for years, but have put off publishing it on the grounds that it looks like the sort of punctuation-riddled code that gives Perl phobics the heebie-jeebies.

A slew of clever people took my script and ported it to other languages — JavaScript, Python, Ruby, PHP, Objective-C, even Nu. Crackerjack work, one and all. But two stand out, at least for my own needs.

David Gouch wrote his own version in JavaScript; his script handles all the edge conditions my script did, and also some others. He also published a list of test cases and the results of my original script, John Resig’s bug-for-bug port to JavaScript of my script, and Gouch’s superior solution. This is the best JavaScript solution I’ve seen; I’m using it in the bookmarklets I use for posting Linked List items.

Aristotle Pagaltzis was kind enough to take my Perl script and refactored it in a straightforward and logical way, fixing some of the edge conditions along the way. He took Gouch’s test cases and turned them into a proper testing suite. The result is better than my original script in every way, and his test suite can be used to improve any implementation.

My thanks to everyone who pitched in on these scripts, and to David Gouch and Aristotle Pagaltzis especially.

Ads via The Deck Ads via The Deck