Re: Producing Unicode-only characters
Re: Producing Unicode-only characters
- Subject: Re: Producing Unicode-only characters
- From: "Nigel Garvey" <email@hidden>
- Date: Wed, 26 Oct 2005 15:38:36 +0100
Emmanuel <email@hidden> wrote on Wed, 26 Oct 2005 10:51:49 +0200
>At 11:01 PM +0100 10/25/05, Nigel Garvey wrote:
>
>>on unicodeCharacter(n)
>> run script "«data utxt" & {n div 4096, n mod 4096 div 256, n mod 256
>>div 16, n mod 16} & "»"
>> end unicodeCharacter
>>etc
>
>Nigel, I read your post quickly (and then Paul's modification following
>Dave's remark), maybe I'm missing something: doesn't that work (and your
>other handlers, too) only for characters with a code lower than 65536?
Mmm. That's true. But then _all_ Unicode numbers are less than 65536 to
AppleScript:
-- "CJK UNIFIED IDEOGRAPH-28CCA"
set a to «data utxt00028CCA» as Unicode text -- 167114
count a
--> 2 -- two characters
So getting the "Unicode numbers" of "Unicode characters" is only
meaningful if you can specify the bit width.
on unicodeNumbers(utxt, bits)
set fref to (open for access file ((path to temporary items as
Unicode text) & "utxt scratch.txt") with write permission)
try
set eof fref to 0
write utxt to fref
if (bits is 16) then
set l to (read fref as short integer from 1) as list
-- Convert to positive long integers.
repeat with i in l
set i's contents to (65536 + i) mod 65536
end repeat
else if (bits is 32) then
set l to (read fref as integer from 1) as list
end if
on error msg
display dialog msg
end try
close access fref
return l
end unicodeNumbers
set u to «data utxt00028CCA» --as Unicode text
unicodeNumbers(u, 16)
--> {2, 36042}
unicodeNumbers(u, 32)
--> {167114}
Getting the Unicode characters of numbers greater than 65535 isn't
meaningful at all in AppleScript. The best you can do is to create
appropriately spaced data and sort it out in your application.
NG
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden