• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Chinese Characters
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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
  • Follow-Ups:
    • Re: Chinese Characters
      • From: Simon Topliss <email@hidden>
References: 
 >Chinese Characters (From: Simon Topliss <email@hidden>)
 >Re: Chinese Characters (From: Philip Aker <email@hidden>)
 >Re: Chinese Characters (From: Simon Topliss <email@hidden>)
 >Re: Chinese Characters (From: "Mark J. Reed" <email@hidden>)

  • Prev by Date: Re: Chinese Characters
  • Next by Date: Re: InDesign CS3 Drop Shadows
  • Previous by thread: Re: Chinese Characters
  • Next by thread: Re: Chinese Characters
  • Index(es):
    • Date
    • Thread