'Flattening'/storing arrays

Dar Scott dsc at swcp.com
Mon Dec 16 16:02:00 EST 2002

On Monday, December 16, 2002, at 01:16 PM, Jan Schenkel wrote:

> RunRev 2.0 has excellent XML support so that should be
> a breeze to implement.

This may run into some special character problems, too.

> Of course you can serialise it
> now with a simple function such as:
> function serialisedArray @pArray
>   put "<array>" & return into tSerialisedArray
>   put the keys of pArray into tKeys
>   repeat for each line tKey in tKeys
>     put "<element key=" & tKey & ">" & \
>     pArray[tKey] & "</element>" & return \
>     after tSerialisedArray
>   end repeat
>   put "</array>" after tSerialisedArray
>   return tSerialisedArray
> end serialisedArray

This has some character limitations, too.  The key must not contain 
lineFeed (see keys()) and must be allowable as an XML attribute.  The 
element must be OK as XML text and especially must not contain text that 
looks like <element..> or </array>

> Remember that if you're working with numbers, upon
> transforming a number into a string, the engine will
> use the 'numberFormat' property, so you may want to
> tweak that before using either method, or apply the
> 'format' function when you serialise the data.

The format idea is a very good one.  A format such as "%4.16e" should 
handle current numbers and %4.32e" might handle lots of future numbers.  
This will work for Inf, -Inf and Nan on only a few platforms and even 
less between.  If you need to handle these, you may want to handle those 
specially or use binaryEncode and binaryDecode.  If you need a text 
file, then you can hex those or go back to handling those specially.

Oh, combine and split may have problems with Inf, -Inf and Nan on some 
systems, too.

It would be nice if we could chose the end-of-line for keys() or--even 
better--have "repeat for each key".  That would make this work easier.

Dar Scott

More information about the Use-livecode mailing list