-- PARENT SCRIPT "MACANSI_CLASS"
--**************************************
-- REQUIRES THE FOLLOWING CODE IN A JS (MOVIE) SCRIPT:
--**************************************
----------------------------------------
-- function RegExpReplaceMulti(str, re, hash, flags){
-- return str.replace(RegExp(re, flags), function(c){return hash[c]?hash[c]:' ';});
-- }
-- function jsPropListToObject(tPropList){
-- tObject = new Object();
-- var cnt = tPropList.count;
-- for (var i=0;i<cnt;i++)
-- tObject[tPropList.getPropAt(i+1).toString()] = tPropList.getAt(i+1);
-- return tObject;
-- }
----------------------------------------
--**************************************
-- USAGE:
--**************************************
-- conv = script("MACANSI_CLASS").new()
-- put conv.ansi2mac("hällö")
-- put conv.mac2ansi("hällö")
property pHashMacAnsi
property pHashAnsiMac
on new me
macAnsiVec=[\
196,197,199,201,209,214,220,225,224,226,228,227,229,231,233,232,\
234,235,237,236,238,239,241,243,242,244,246,245,250,249,251,252,\
134,176,162,163,167,149,182,223,174,169,153,180,168, 32,198,216,\
218,177, 32, 32,165,181, 32, 32, 32, 32, 32,170,186, 32,198,216,\
191,161,172, 32,131,152, 32,171,187,133,160,192,195,213,140,156,\
150,151,147,148,145,146,215, 32,255,159, 32,128,139,155, 32, 32,\
135,183,130,132,137,194,202,193,203,200,205,206,207,204,211,212,\
32,210,218,219,217, 32,136,152,175, 32, 32,176,184, 32, 32, 32]
MacAnsiPropList = [:]
AnsiMacPropList = [:]
repeat with i = 1 to 128
c = macAnsiVec[i]
if c<>32 then
MacAnsiPropList[numtochar(127+i)] = numtochar(c)
AnsiMacPropList[numtochar(c)] = numtochar(127+i)
end if
end repeat
pHashMacAnsi = jsPropListToObject(MacAnsiPropList)
pHashAnsiMac = jsPropListToObject(AnsiMacPropList)
return me
end
----------------------------------------
-- converts MacRoman encoded string to WinLatin1 (Windows-1252) encoded string
----------------------------------------
on mac2ansi (me, str)
return RegExpReplaceMulti(str, "[\x80-\xFF]", pHashMacAnsi, "g")
end
----------------------------------------
-- converts WinLatin1 (Windows-1252) encoded string to MacRoman encoded string
----------------------------------------
on ansi2mac (me, str)
return RegExpReplaceMulti(str, "[\x80-\xFF]", pHashAnsiMac, "g")
end