Alternate Form of printKeys()

Bob Sneidar bobs at twft.com
Thu Jan 26 18:12:31 EST 2012


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



More information about the use-livecode mailing list