Re: interesting discovery (trying to get record labels as strin
Re: interesting discovery (trying to get record labels as strin
- Subject: Re: interesting discovery (trying to get record labels as strin
- From: Nigel Garvey <email@hidden>
- Date: Wed, 5 Dec 2001 14:10:40 +0000
Arthur J Knapp wrote on Tue, 04 Dec 2001 10:56:10 -0500:
>
property k0 : ASCII character 0
>
property k1 : ASCII character 1
>
property k2 : ASCII character 2
>
property k4 : ASCII character 4
>
>
property k0000 : k0 & k0 & k0 & k0
>
property k0001 : k0 & k0 & k0 & k1
>
property k0002 : k0 & k0 & k0 & k2
>
property k0004 : k0 & k0 & k0 & k4
>
>
on IntegerToBytes(n)
>
return ({{a:n}} as string)'s text -4 thru -1
>
end IntegerToBytes
>
>
on StringToCodes(str)
>
>
set o to text item delimiters
>
try
>
set str to str's items -- length must be < approx 4050
>
set itemCount to IntegerToBytes(str's length)
>
>
set typeStr to "long" & k0004 & k0 & k0 & k0
>
set text item delimiters to {typeStr}
>
set str to typeStr & str
>
>
set str to itemCount & k0000 & str
>
set str to "list" & IntegerToBytes(str's length) & str
>
>
set str to k0002 & k0000 & "TEXT" & k0001 & "a" & k0 & str
>
set str to IntegerToBytes(str's length) & str
>
>
set str to k0001 & k0000 & "usrflist" & str
>
>
on error m number n
>
set text item delimiters to o
>
error m number n
>
end try
>
set o to text item delimiters
>
>
return a of (str as record)
>
>
end StringToCodes
>
>
StringToCodes("Hello World")
>
--
>
--> {72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100}
Even though it relies on a bug that's under threat of cure, this is
totally brilliant! :-)
The complementary routine might look something like this:
on codesToString(codes)
set str to {{a:codes as list}} as string
set typeOffset to offset of "long" in str
set typeStr to text typeOffset thru (typeOffset + 10) of str
set o to text item delimiters
set text item delimiters to {typeStr}
set str to text items 2 thru -1 of str
set text item delimiters to {""}
set str to str as string
set text item delimiters to o
return str
end codesToString
codesToString({72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100})
--> "Hello World"
NG