On 17/01/2012, at 5:04 PM, Shane Stanley wrote:
But it suffers from the same problem as most of the others posted here: it assumes you never use anything other than ASCII characters. The people of Neuchâtel might not be impressed.
To be safe, you'd be better off using something based on the ICU libraries, like Satimage.osax or an AppleScriptObjC solution.
(Why do we still have this nonsense? Heck, the Unicode Consortium turned 21 just two weeks ago...)
For the record, my pure AppleScript solution seems to work fine:
CamelCase("The people of Neuchâtel might not be impressed")
gives:
thePeopleOfNeuchâtelMightNotBeImpressed
While I'm here,I should also point out that there have been at least three different interpretations of what camelCase is, by posters on this thread. WikiPedia describes it as (I'm paraphrasing) words joined without spaces, capitalising the first letter of each word, optionally capitalising the first letter of the first word.
I've always taken it to mean the first letter of the first wordnot capitalised, which is what my script does.
on CamelCase(oldText) set camelList to {} & LowerCase(first word in oldText) repeat with thisWord in the rest of the words in oldText set end in camelList to UpperCase(first character in thisWord) set remainingText to (rest of characters in thisWord as text) if remainingText is not "" then set end in camelList to LowerCase(remainingText) end if end repeat set camelText to camelList as text return camelText end CamelCase
but you could alter it to capitalise all words, if you want:
on TitleCaseJoined(oldText) set newList to {} repeat with thisWord in the words in oldText set end in newList to UpperCase(first character in thisWord) set remainingText to (rest of characters in thisWord as text) if remainingText is not "" then set end in newList to LowerCase(remainingText) end if end repeat set newText to newList as text return newText end TitleCaseJoined
Thanks, Tom
Tom Brodhurst-Hill BareFeetWare -- iPhone/iPad/iPod and Mac software development, specialising in databases -- |