• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
camelCase
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

camelCase


  • Subject: camelCase
  • From: BareFeetWare <email@hidden>
  • Date: Tue, 17 Jan 2012 17:21:12 +1100

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.
http://en.wikipedia.org/wiki/CamelCase

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
email@hidden
--
Twitter: http://twitter.com/barefeetware/
Facebook: http://www.facebook.com/BareFeetWare

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Follow-Ups:
    • Re: camelCase
      • From: Shane Stanley <email@hidden>
References: 
 >ScriptingAddition for camelcase (From: Ronald Hofmann <email@hidden>)
 >Re: ScriptingAddition for camelcase (From: BareFeetWare <email@hidden>)
 >Re: ScriptingAddition for camelcase (solved via PHP) (From: Ronald Hofmann <email@hidden>)
 >Re: ScriptingAddition for camelcase (solved via PHP) (From: Shane Stanley <email@hidden>)

  • Prev by Date: Re: ScriptingAddition for camelcase (solved via PHP)
  • Next by Date: Re: camelCase
  • Previous by thread: Re: ScriptingAddition for camelcase (solved via PHP)
  • Next by thread: Re: camelCase
  • Index(es):
    • Date
    • Thread