1. -- PARENT SCRIPT "MACANSI_CLASS"
  2.  
  3. --**************************************
  4. -- REQUIRES THE FOLLOWING CODE IN A JS (MOVIE) SCRIPT:
  5. --**************************************
  6. ----------------------------------------
  7. -- function RegExpReplaceMulti(str, re, hash, flags){
  8. --   return str.replace(RegExp(re, flags), function(c){return hash[c]?hash[c]:' ';});
  9. -- }
  10. -- function jsPropListToObject(tPropList){
  11. --   tObject = new Object();
  12. --   var cnt = tPropList.count;
  13. --   for (var i=0;i<cnt;i++)
  14. --     tObject[tPropList.getPropAt(i+1).toString()] = tPropList.getAt(i+1);
  15. --   return tObject;
  16. -- }
  17. ----------------------------------------
  18.  
  19. --**************************************
  20. -- USAGE:
  21. --**************************************
  22. -- conv = script("MACANSI_CLASS").new()
  23. -- put conv.ansi2mac("hällö")
  24. -- put conv.mac2ansi("hällö")
  25.  
  26. property pHashMacAnsi
  27. property pHashAnsiMac
  28.  
  29. on new me
  30.   macAnsiVec=[\
  31.   196,197,199,201,209,214,220,225,224,226,228,227,229,231,233,232,\
  32.   234,235,237,236,238,239,241,243,242,244,246,245,250,249,251,252,\
  33.   134,176,162,163,167,149,182,223,174,169,153,180,168, 32,198,216,\
  34.   218,177, 32, 32,165,181, 32, 32, 32, 32, 32,170,186, 32,198,216,\
  35.   191,161,172, 32,131,152, 32,171,187,133,160,192,195,213,140,156,\
  36.   150,151,147,148,145,146,215, 32,255,159, 32,128,139,155, 32, 32,\
  37.   135,183,130,132,137,194,202,193,203,200,205,206,207,204,211,212,\
  38.    32,210,218,219,217, 32,136,152,175, 32, 32,176,184, 32, 32, 32]
  39.   MacAnsiPropList = [:]
  40.   AnsiMacPropList = [:]
  41.   repeat with i = 1 to 128
  42.     c = macAnsiVec[i]
  43.     if c<>32 then
  44.       MacAnsiPropList[numtochar(127+i)] = numtochar(c)
  45.       AnsiMacPropList[numtochar(c)] = numtochar(127+i)
  46.     end if
  47.   end repeat
  48.   pHashMacAnsi = jsPropListToObject(MacAnsiPropList)
  49.   pHashAnsiMac = jsPropListToObject(AnsiMacPropList)
  50.   return me
  51. end
  52.  
  53. ----------------------------------------
  54. -- converts MacRoman encoded string to WinLatin1 (Windows-1252) encoded string
  55. ----------------------------------------
  56. on mac2ansi (me, str)
  57.   return RegExpReplaceMulti(str, "[\x80-\xFF]", pHashMacAnsi, "g")
  58. end
  59.  
  60. ----------------------------------------
  61. -- converts WinLatin1 (Windows-1252) encoded string to MacRoman encoded string
  62. ----------------------------------------
  63. on ansi2mac (me, str)
  64.   return RegExpReplaceMulti(str, "[\x80-\xFF]", pHashAnsiMac, "g")
  65. end
  66.  
[raw code]