Alternate Form of printKeys()

Peter M. Brigham, MD pmbrig at gmail.com
Sat Jan 28 08:35:19 EST 2012


One little tweak:

instead of 

>        if theKey is not a number then
>            replace theKey with quote & theKey & quote in theKeyList
>        end if

use 

if theKey is not a number then
   replace "[" & theKey & "]" with "[" & quote & theKey & quote & "]" in theKeyList
end if

I tried it with keys like [second][c][2] and your original replacement line gave me ["se"c"ond"] as one of the entries.

What I liked about the original handlers was that the previous altPrintKeys would output a textual representation of the array in an intuitive outline form, so you could see at a glance the structure and contents of the array. Your new function converts an array to a text string but it's really hard to tell by looking at the string how the array is structured, so it has limited value to me. For what purpose would you be using the new version of these functions?

-- Peter

Peter M. Brigham
pmbrig at gmail.com
http://home.comcast.net/~pmbrig


On Jan 26, 2012, at 6:12 PM, Bob Sneidar wrote:

> Here are the functions. I have tested them and they seem to be fine, but any bug reports would be appreciated. Note that there is another distinct advantage of these functions over the original printKeys(): These functions allow for returns and tabs in the values. I convert them to ascii(30) and ascii(11) respectively when I return text and back again when I return an array. 
> 
> Also bear in mind I do no error checking. Who knows what would happen if you pass something other than what is expected. Hang on to your socks! :-)
> 
> function altPrintKeys @pArray, theKeyList, pFullData
>    put numtochar(11) into vertTab
>    put numtochar(30) into altCr
>    put the keys of pArray into theKeys
>    sort theKeys numeric
> 
>    repeat for each line theKey in theKeys
>        put "[" & theKey & "] " after theKeyList
>        if theKey is not a number then
>            replace theKey with quote & theKey & quote in theKeyList
>        end if
>        if pArray[theKey] is an array then
>            put pArray[theKey] into theTempArray
>            put altPrintKeys(theTempArray, theKeyList, pFullData) after theText
>            put empty into the last word of theKeyList
>            delete the last char of theKeyList
>            put cr into the last char of theText
>        else
>            put "pArray " & the last word of theKeyList into theKeyName
>            -- put "put " & theKeyName & " into theValue" into theCommand
>            -- do theCommand
>            put the value of theKeyName into theValue
>            replace tab with vertTab in theValue
>            replace return with altCr in theValue
>            put theKeyList & tab & theValue & comma after theText
>            put empty into the last word of theKeyList
>            delete the last char of theKeyList
>        end if
>    end repeat
> 
>    return theText
> end altPrintKeys
> 
> function altKeysToArray theText
>    put numtochar(11) into vertTab
>    put numtochar(30) into altCr
>    repeat for each line theRecord in theText
>        repeat for each item theKeyData in theRecord
>            put the itemdelimiter into theOldDelim
>            set the itemdelimiter to tab
>            put item 1 of theKeyData into theKeyList
>            put item 2 of theKeyData into theValue
>            replace vertTab with tab in theValue
>            replace altCr with return in theValue
>            set the itemdelimiter to theOldDelim
>            put "put " & quote & theValue & quote & " into theArrayA " & theKeylist into theCommand
>            do theCommand
>        end repeat
>    end repeat
> 
>    return theArrayA
> end altKeysToArray
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode





More information about the use-livecode mailing list