Re: Producing Unicode-only characters
Re: Producing Unicode-only characters
- Subject: Re: Producing Unicode-only characters
- From: "Nigel Garvey" <email@hidden>
- Date: Tue, 25 Oct 2005 23:01:06 +0100
has wrote on Tue, 25 Oct 2005 13:30:41 +0100:
>kai wrote:
>
>>One method that I've been using to produce Unicode-only characters is:
>>
>>---------------
>>
>>«data utxt3048» as Unicode text
>>
>>---------------
>>
>>While this seems to be substantially faster than using a shell
>>script, I'm just wondering if there's a potential downside...
>
>Known problems are:
>- crap readability
>- doesn't work pre-Panther (and can result in crashes).
There's a couple of 'run script' variants that work in Jaguar. One is:
script
«data utxt3048»
end script
run script result
This works in Tiger to, but can take about 2190 times as long as kai's
suggestion! A bit faster is the string version:
run script "«data utxt3048»"
... which of course makes a nice basis for a Unicode character handler:
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
unicodeCharacter(12360)
You could arrange for the above handler to take a hexadecimal string instead.
I can't find a really satisfactory way to get the number from the
character, though there are two that are much faster than Chris's shell
script. The faster of the two exploits the single-record-list-to-string
coercion bug, which still exists in Tiger:
on unicodeNumber(c)
set s to {{a:character 1 of c}} as string
(ASCII number (character -2 of s)) * 256 + (ASCII number (character -
1 of s))
end unicodeNumber
Otherwise, as Chris mentioned, there's the temporary file approach. You
need to set a suitable location for the file and perhaps delete it after use:
on unicodeNumber(c)
set fref to (open for access file ((path to desktop as Unicode text)
& "Utxt chr.txt") with write permission)
try
set eof fref to 0
write character 1 of c to fref
set n to read fref as short integer from 1
end try
close access fref
return n
end unicodeNumber
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