Thanks Dick - I hadn't thought about handling common cases differently. Good idea!

Phil


On 1/11/10 12:10 PM, Dick Kriesel wrote:
On 1/10/10 1:25 PM, "Phil Davis"<[email protected]>  wrote:

The things some people do for fun...  ;-)
... can make others want to get in on the fun, like by fixing something that
ain't broke.  Here's an elaboration on your idea that handles your sample
data more than twice as fast, primarily by avoiding the "do" for typical
cases.

Thanks for the cue, Phil.

-- Dick


<postscript_with_line_wraps>

function table_split tTable,pLineDel,pItemDel
    filter tTable without empty
    set the lineDelimiter to coalesce(pLineDel,cr)
    set the itemDelimiter to coalesce(pItemDel,tab)
    switch number of items in line 1 of tTable - 1 -- number of dimensions
       case 1
          repeat for each line tLine in tTable
             put item 2 of tLine into tArray[item 1 of tLine]
          end repeat
          break
       case 2
          repeat for each line tLine in tTable
             put item 3 of tLine into tArray[item 1 of tLine][item 2 of
tLine]
          end repeat
          break
       case 3
          repeat for each line tLine in tTable
             put item 4 of tLine into tArray[item 1 of tLine][item 2 of
tLine][item 3 of tLine]
          end repeat
          break
       default
          repeat for each line tLine in tTable
             do "put last item of tLine into tArray["&  replaceText(item 1 to
-2 of tLine,the itemDelimiter,"][")&  "]"
          end repeat
    end switch
    return tArray
end table_split

function coalesce -- return the first non-empty parameter
    repeat with i = 1 to the paramCount
       if param(i) is not empty then
          return param(i)
       end if
    end repeat
end coalesce

</postscript_with_line_wraps>


_______________________________________________
use-revolution mailing list
[email protected]
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution


--
Phil Davis

PDS Labs
Professional Software Development
http://pdslabs.net

_______________________________________________
use-revolution mailing list
[email protected]
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution

Reply via email to