Re: Scripts works with OSX 10.5 but not earlier because of Unicode
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