titlecase is a Perl script, originally by the creator of smartypants and Markdown, John Gruber, this fork is made by Aristotle Pagaltzis.
Personally, I don’t write in TitleCase in almost all cases — no pun intended, but this Perl script is interesting just as the smartypants. It includes a test suite program that runs 31 tests, the following just the first five, which should be enough to get the idea:
For step-by-step directions email someone@gmail.com
For Step-by-Step Directions Email someone@gmail.com
2lmc Spool: 'Gruber on OmniFocus and Vapo(u)rware'
2lmc Spool: 'Gruber on OmniFocus and Vapo(u)rware'
Have you read “The Lottery”?
Have You Read “The Lottery”?
your hair[cut] looks (nice)
Your Hair[cut] Looks (Nice)
People probably won't put http://foo.com/bar/ in titles
People Probably Won't Put http://foo.com/bar/ in Titles
You can see it cover cases you probably have not thought about, there is some more details on John Gruber’s page, noting about a few cases and why:
It’s pretty easy to write a non-clever title-casing function. The simplest way is to just capitalize the first letter of every word. That’s not right, though, because it’ll leave you with capitalized small words like if, in, of, on, etc. What you want is something that not only knows not to capitalize such words, but will un-capitalize them if they’re erroneously capitalized in the input.
titlecase was released on 2008-05-20, then an update on 2008-08-13, including Aristotle Pagaltzis’ improvements on the original Perl script along with other languages like JavaScript, Python, Ruby, PHP, …. The last update of this fork was on 2012-02-06. It’s licensed under the MIT License, and titlecase is:
Language | files | blank | comment | code |
---|---|---|---|---|
Perl | 1 | 13 | 23 | 46 |
Only 46 lines, sweet short!
Since I code in Python sometimes, I can tell you that str.title method is absolutely can’t compare with this. But most of time, that’s sufficient. Why would you put email address or URL in something like heading line? To me, if you write like that, I probably wouldn’t even click. It doesn’t matter if it’s about technical stuff, it just doesn’t feel right to see email or URL in titles.
I don’t know if anyone has packaged this Perl script, but if someone does need to convert text to TitleCase, this script could be used easily, much simpler and more correct than this. If I were to use this, in Vim, just select and filter the selection through this script, voilĂ !
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.