--****************************************************************************
-- Script: NULL_ENCODER
-- Version: 0.3
-- Date: 2006/08/28
-- Author: Valentin Schmidt
-- Description:
-- simple encoder/decoder for binary strings so they can be send
-- with postNetText()
--
--****************************************************************************
----------------------------------------
-- optimized for director's performance degradation when handling large strings
----------------------------------------
on null_encode (str)
subLengthLim = 5000
chunks = []
tmp = ""
len = str.length
repeat with i = 1 to len
c = str.char[i]
-- escape character c with "\" & numtochar(chartonum(c)+32)
-- if c is either numtochar(0), numtochar(13) or "\"
case (chartonum(c)) of
0: put "\ " after tmp
13: put "\-" after tmp
92: put "\|" after tmp
otherwise:
put c after tmp
end case
if length(tmp) > subLengthLim then --- cach segment in array, start new out string
chunks.append(tmp)
tmp = ""
end if
end repeat
-- assemble as large string
ret = ""
repeat with str in chunks
put str after ret
end repeat
put tmp after ret
return ret
end
----------------------------------------
-- optimized for director's performance degradation when handling large strings
----------------------------------------
on null_decode (str)
subLengthLim = 5000 -- adjust!
chunks = []
tmp = ""
len = str.length
repeat with i = 1 to len
if str.char[i] = "\" then
put numtochar(chartonum(str.char[i+1])-32) after tmp
i = i + 1
else
put str.char[i] after tmp
end if
if length(tmp) > subLengthLim then --- cach segment in array, start new out string
chunks.append(tmp)
tmp = ""
end if
end repeat
-- assemble as large string
ret = ""
repeat with str in chunks
put str after ret
end repeat
put tmp after ret
return ret
end