• 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: Scripts works with OSX 10.5 but not earlier because of Unicode
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Scripts works with OSX 10.5 but not earlier because of Unicode


  • Subject: Re: Scripts works with OSX 10.5 but not earlier because of Unicode
  • From: "Mark J. Reed" <email@hidden>
  • Date: Fri, 11 Apr 2008 16:54:13 -0400

On Fri, Apr 11, 2008 at 4:32 PM, Mark J. Reed <email@hidden> wrote:
>  If you're generating AS from Java, you essentially have to look at
>  each char in the string and if its value is > 127 output the data utxt
>  form.

Humble example:

class AppleScripter
{
  static public String toAppleScript(String input)
  {
      char[] chars = input.toCharArray();
      StringBuffer result = new StringBuffer("\"");
      boolean inData = false;
      for (int i=0; i<chars.length; ++i)
      {
         char codePoint = chars[i];
         if (codePoint < 0x80)
         {
             if (inData)
             {
                 result.append("» as unicode text) && \"");
                 inData = false;
             }
             if (codePoint == '"' || codePoint == '\\')
             {
               result.append("\\");
             }
             result.append(codePoint);
         }
         else
         {
            if (!inData)
            {
               result.append("\" && («data utxt");
               inData = true;
            }
            String word = Integer.toString(codePoint, 16);
            for (int j=0; j < 4 - word.length(); ++j)
            {
              result.append("0");
            }
            result.append(word);
         }
      }
      if (inData)
      {
        result.append("» as unicode text)");
      }
      else
      {
        result.append("\"");
      }
      return result.toString();
  }
}

Thus, given:

public class Foo {  public static void main(String[] args)
  {
      for (int i=0; i<args.length; ++i)
      {
        System.out.println(AppleScripter.toAppleScript(args[i]));
      }
  }
}

I can do this:

$ java Foo 'be\"eǿ'
"be\\\"e" && («data utxt01ff» as unicode text)

--
Mark J. Reed <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

References: 
 >Scripts works with OSX 10.5 but not earlier because of Unicode (From: Paul Taylor <email@hidden>)
 >Re: Scripts works with OSX 10.5 but not earlier because of Unicode (From: Christopher Nebel <email@hidden>)
 >Re: Scripts works with OSX 10.5 but not earlier because of Unicode (From: Paul Taylor <email@hidden>)
 >Re: Scripts works with OSX 10.5 but not earlier because of Unicode (From: "Mark J. Reed" <email@hidden>)

  • Prev by Date: Re: Scripts works with OSX 10.5 but not earlier because of Unicode
  • Next by Date: Re: When can you use the 'whose' clause (Filter)
  • Previous by thread: Re: Scripts works with OSX 10.5 but not earlier because of Unicode
  • Next by thread: Re: Scripts works with OSX 10.5 but not earlier because of Unicode
  • Index(es):
    • Date
    • Thread