Re: Chinese Characters
Re: Chinese Characters
- Subject: Re: Chinese Characters
- From: Simon Topliss <email@hidden>
- Date: Wed, 5 Aug 2009 22:01:44 +0100
Well, Mark, as a regular "eschewer", I look forward to comparing the
performance of each approach!
On 5 Aug 2009, at 21:47, Mark J. Reed wrote:
Some minor tweaks.
It occurs to me that the hex conversions are a little clearer if
they're parallel:
on fromHex(someValue)
do shell script " dc <<<'16i" & someValue & "p'"
end fromHex
on toHex(someValue)
do shell script " dc <<<'16o" & someValue & "p'"
end toHex
To do it the hard way for the "do shell script" eschews:
on fromHex(someValue)
set decimalValue to 0
repeat with digit in characters of someValue
if digit >= "a" and digit <= "f" then
set value to 10 + (id of digit) - (id of "a")
else if digit >= "A" and digit <= "F" then
set value to 10 + (id of digit) - (id of "A")
else
set value to digit as integer
end if
set decimalValue to decimalValue * 16 + value
end repeat
return decimalValue
end fromHex
on toHex(someValue)
set hexString to ""
repeat while someValue is not 0
set value to someValue mod 16
set someValue to someValue div 16
if value < 10 then
set digit to value as text
else
set digit to character id (id of "A" + value - 10)
end if
set hexString to digit & hexString
end repeat
return hexString
end toHex
And I decided the Unicode blocks were more useful as records:
on findBlock(someCharacter)
if (count UnicodeBlocks) is 0 then
repeat with aLine in (paragraphs of (read POSIX file
"/System/Library/Perl/5.8.8/unicore/Blocks.txt"))
if length of aLine is not 0 and text 1 of aLine is not
"#" then
set text item delimiters to "; "
set blockRange to text item 1 of aLine
set blockDescription to text item 2 of aLine
set text item delimiters to ".."
set blockStart to fromHex(text item 1 of blockRange)
set blockEnd to fromHex(text item 2 of blockRange)
set end of UnicodeBlocks to {rangeStart: blockStart,
rangeEnd: blockEnd, description: blockDescription}
end
end repeat
end if
set someCharacterId to id of someCharacter
repeat with aBlock in UnicodeBlocks
if someCharacterId >= rangeStart of aBlock and someCharacterId
<= rangeEnd of aBlock
return aBlock as record
end if
end repeat
end findBlock
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (applescript-
email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to 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