On 24 Dec 2015, at 7:06 AM, Yvan KOENIG <
email@hidden> wrote:
(1) Your camelCase handler maybe fine for English users - although I dislike the fact that it use the deprecated ASCII number.
For non English users, it fail to convert the accented chars.
I fear you're missing what Steve means by camelCase. He means as generally used for variable names in programming, so "un éléphant ça trompe" would become "unÉléphantÇaTrompe". However, in this case I suspect accents would be out; they are usually not allowed in variable names in programming languages.
You're right that he should use id rather than ASCII number, but he's on 10.6 so ASObjC is out. But for ASObjC users there's a method that capitalizes just the first character of words: capitalizedString. So if here were on 10.9 or later, he could use:
on camelCase(aPhrase)
set firstWord to current application's NSString's stringWithString:(word 1 of aPhrase)
set firstWord to firstWord's |lowercaseString|() as text
set restOfPhrase to current application's NSString's stringWithString:(text from word 2 to -1 of aPhrase)
set restOfPhrase to (restOfPhrase's |capitalizedString|()'s stringByReplacingOccurrencesOfString:space withString:"") as text
return firstWord & restOfPhrase
end camelCase
However, non-English-speaking users might still need to watch out for éléphants, to remove the accents. I suspect that to do that in simple AppleScript would mean building a list of the ids of accented characters, and their equivalents. But if you wanted a foolproof ASObjC handler that also did that, it would be:
on camelCase(aPhrase)
set firstWord to current application's NSString's stringWithString:(word 1 of aPhrase)
set firstWord to firstWord's |lowercaseString|()
set restOfPhrase to current application's NSString's stringWithString:(text from word 2 to -1 of aPhrase)
set restOfPhrase to restOfPhrase's capitalizedString()'s stringByReplacingOccurrencesOfString:space withString:""
set newPhrase to firstWord's stringByAppendingString:restOfPhrase
return (newPhrase's stringByFoldingWithOptions:(current application's NSDiacriticInsensitiveSearch) locale:(missing value)) as text
end camelCase