• 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
Getting Unicode Number
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Getting Unicode Number


  • Subject: Getting Unicode Number
  • From: Joseph Weaks <email@hidden>
  • Date: Sun, 06 Feb 2005 09:08:21 -0600

I'm working on a routine to encode Unicode characters into xhtml entities.
I've been looking at Emmanuel's UnicodeNumbers(s) routine (at
http://www.satimage.fr/software/en/unicode_and_applescript.html), but some
of it is puzzling to me.

Here is the routine:

on UTFTempFile()
     ("" & (path to "temp" from user domain) & "utf_smile_file")
 end TempFile

 on UnicodeNumber(s)
     set f to UTFTempFile()
     set r to open for access file f with write permission
     try
         set eof r to 0
         write s to r as Unicode text
         close access r
         set ss to read (f as alias)
         set n to 0
         try
             repeat
                 set n to (ASCII number of character 1 of ss) + 256 * n
                 set ss to text 2 thru -1 of ss
             end repeat
         end try
         return n
     on error errstr number errnum
         try
             close access r
         end try
         error errstr number errnum from s
     end try
 end UnicodeNumber

Question 1:
Why is there a need to write a Unicode string to a temp file and then read
it when it is already in a variable?

Question 2:
The above routine is said to duplicate ASCII character command for Unicode
(decimal I'm guessing) characters, but I'm not seeing that. For instance,
when ASCII character of x is passed a string of more than one character, it
returns the ASCII number of the first character, but in the above routine,
it seems to be adding up the decimial values of all the characters. So in
the above routine, I need to be sure to pass only one character at a time?

Question 3:
I don't really understand what's going on with the meat of the script,
namely: "set n to (ASCII number of character 1 of ss) + 256 * n". Setting n
to zero and then setting it to the ascii number of the previous character is
not making sense to me. Could someone explain it?

Question 4:
My goal is to convert characters into the XHTML entities. So, once I have
each decimal value, I can check to see if it's over 126, right? If it's over
that, then it needs to be encoded as an entity?

Question 5:
My routine will be working on a Unicode string on the clipboard, so is it
still necessary to write to a temp file? Any suggestions on how to make it
so?

Thanks,
Joe Weaks


 _______________________________________________
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

  • Follow-Ups:
    • Re: Getting Unicode Number
      • From: Emmanuel <email@hidden>
  • Prev by Date: is there an application bundle equivalent on the PC ?
  • Next by Date: Re: Getting Unicode Number
  • Previous by thread: Re: is there an application bundle equivalent on the PC ?
  • Next by thread: Re: Getting Unicode Number
  • Index(es):
    • Date
    • Thread