Feature request: merge function!

hh hh at hyperhh.de
Fri Jan 18 10:35:09 EST 2019


Until parametrization is implemented for LC 9 one could use
the following generalization of Andre's method for David.
This is still fast enough because replace is so fast in LC.

David would call merge2(string, "{{", "}}").
To make merge xml safe use e.g. merge2(string,,,"<1>","<2>")

Of course you have to make all variables that you use in string
to local script variables (with that accessible by merge2)
[OR split merge2 into 3 parts: beforeMerge, merge, afterMerge].

-- The following works in LC 6/7/8/9.
-- t_1 is the new opening tag replacing [[
-- t_2 is the new closing tag replacing ]]
-- t_3 is the new opening tag replacing <?
-- t_4 is the new closing tag replacing ?>
-- Leave a t_x empty to use the merge-opening/closing tag.
--> The t_i+1 must not contain t_1 to t_i for all i <--

function merge2 s,t_1,t_2,t_3,t_4 
 put t_1 is not empty into c1
 put t_2 is not empty into c2
 put t_3 is not empty into c3
 put t_4 is not empty into c4
 if c1 then
    replace "[[" with numToChar(1) in s
    replace t_1 with "[[" in s
 end if
 if c2 then
    replace "]]" with numToChar(2) in s
    replace t_2 with "]]" in s
 end if
 if c3 then
    replace "<?" with numToChar(3) in s
    replace t_3 with "<?" in s
 end if
 if c4 then
    replace "?>" with numToChar(4) in s
    replace t_4 with "?>" in s
 end if
 put merge(s) into s
 if c1 then replace numToChar(1) with "[[" in s
 if c2 then replace numToChar(2) with "]]" in s
 if c3 then replace numToChar(3) with "<?" in s
 if c4 then replace numToChar(4) with "?>" in s
 return s
end merge2




More information about the use-livecode mailing list