Re: Considering case...
Re: Considering case...
- Subject: Re: Considering case...
- From: Bill Cheeseman <email@hidden>
- Date: Sat, 22 Feb 2014 15:02:42 -0500
On Feb 22, 2014, at 1:15 PM, David Crowe <email@hidden> wrote:
> Why does this not work? It prints out that "E" is lower case.
>
>
> set c to "E"
> considering case
> if "a" ≤ c and c ≤ "z" then
> display dialog "Character '" & c & "' is lower case."
> end if
> end considering
>
> I've tried this on Mavericks and 10.6 and get the same thing. Using "Smile" and the standard AppleScript editor gives the same result.
>
> What am I missing?
Your test assumes that AppleScript sorts the lowercase characters in the Latin alphabet as a group separately from the uppercase characters, for purposes of the 'less than or equal' or 'comes before' operator in 'ignoring case' blocks. This is true as to numeric ASCII values or Unicode code values for the Latin alphabet. I think text in AppleScript 1.0 was based more or less on ASCII values, and, although AppleScript 2.0 text is based on Unicode according to the documentation, the Unicode code values of the Latin alphabet are the same as the ASCII values. So I can see why you would expect your script to work.
But testing shows that the lowercase and uppercase letters are in fact intermixed in AppleScript 2.0 when compared using this operator in 'ignoring case' blocks (I no longer have AppleScript 1.0 to test). The order is not A..Za..z as in ASCII and Unicode, but aAbB..yYzZ. The following script statements all return 'true':
"a" ≤ "A"
"A" ≤ "b"
..
"Y" ≤ "z"
"z" ≤ "Z"
This answers your question, because "a" <= "E" and "E" <= "z" are both true, at least in AppleScript 2.0.
I've never seen this documented or discussed before, and I don't know what the reason for designing it this way was. It may just be a consequence of the fact that AppleScript comparisons normally do not consider case, so that "a" and "A" are considered equal and both of them come before "b" and "B". I can see how the 'considering case' statement might most easily have been implemented by leaving them in that order while noting the difference in case. This is also consistent with the basic credo that AppleScript is "plain English" -- only us geeks know about ASCII values and Unicode code values.
To make your script work as you expect it to work, compare the 'id' properties of the characters instead of the characters themselves. The 'id' properties are the ASCII values or Unicode code values of the characters. Like this:
set c to "E"
considering case
if id of "a" ≤ id of c and id of c ≤ id of "z" then
display dialog "Character '" & c & "' is lower case."
end if
end considering
--
Bill Cheeseman - email@hidden
_______________________________________________
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