1. --****************************************************************************
  2. -- Script:   NULL_ENCODER
  3. -- Version:  0.3
  4. -- Date:     2006/08/28
  5. -- Author:   Valentin Schmidt
  6.  
  7. -- Description:
  8. -- simple encoder/decoder for binary strings so they can be send
  9. -- with postNetText()
  10. --
  11. --****************************************************************************
  12.  
  13. ----------------------------------------
  14. -- optimized for director's performance degradation when handling large strings
  15. ----------------------------------------
  16. on null_encode (str)
  17.  
  18.   subLengthLim = 5000
  19.   chunks = []
  20.   tmp = ""
  21.  
  22.   len = str.length
  23.   repeat with i = 1 to len
  24.    
  25.     c = str.char[i]
  26.     -- escape character c with "\" & numtochar(chartonum(c)+32)
  27.     -- if c is either numtochar(0), numtochar(13) or "\"
  28.     case (chartonum(c)) of
  29.       0:  put "\ " after tmp
  30.       13: put "\-" after tmp
  31.       92: put "\|" after tmp
  32.        
  33.       otherwise:
  34.         put c after tmp
  35.     end case
  36.    
  37.     if length(tmp) > subLengthLim then --- cach segment in array, start new out string
  38.       chunks.append(tmp)
  39.       tmp = ""
  40.     end if
  41.    
  42.   end repeat
  43.  
  44.   -- assemble as large string
  45.   ret = ""
  46.   repeat with str in chunks
  47.     put str after ret
  48.   end repeat
  49.   put tmp after ret
  50.  
  51.   return ret
  52. end
  53.  
  54. ----------------------------------------
  55. -- optimized for director's performance degradation when handling large strings
  56. ----------------------------------------
  57. on null_decode (str)
  58.  
  59.   subLengthLim = 5000 -- adjust!
  60.   chunks = []
  61.   tmp = ""
  62.  
  63.   len = str.length
  64.   repeat with i = 1 to len
  65.     if str.char[i] = "\" then
  66.       put numtochar(chartonum(str.char[i+1])-32) after tmp
  67.       i = i + 1
  68.     else
  69.       put str.char[i] after tmp
  70.     end if
  71.    
  72.     if length(tmp) > subLengthLim then --- cach segment in array, start new out string
  73.       chunks.append(tmp)
  74.       tmp = ""
  75.     end if
  76.    
  77.   end repeat
  78.  
  79.   -- assemble as large string
  80.   ret = ""
  81.   repeat with str in chunks
  82.     put str after ret
  83.   end repeat
  84.   put tmp after ret
  85.  
  86.   return ret
  87. end
[raw code]