Re: Feature request: merge function!
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 -- 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(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 return s end merge2 ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Feature request: merge function!
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 -- 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(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 return s end merge2 ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Feature request: merge function!
That would be great Mark :) Andre the general function I use for munging text uses regular expressions as my head exploded long ago with too many custom string munging functions :) *command* fedwiki_MergeCurlyArray @templateArray, itemID, curlyArray > *put* fedwiki_GetStoryItemText (templateArray, itemID) into itemText > text_MergeCurly itemText, curlyArray fedwiki_SetStoryItemText templateArray, itemID, itemText *end* fedwiki_MergeCurlyArray > > *command* text_MergeCurly @someText, curlyArray > *repeat* for each key curlyLabel in curlyArray > *put* curlyArray [curlyLabel] into curlyReplacement > *put* "(\{\{\s*" & curlyLabel & "\s*\}\})" into someReg > text_StripReg someText, someReg, curlyReplacement *end* > *repeat* *end* text_MergeCurly *command* text_StripReg @wikiText, someReg, pReplaceText > *local* refStart, refEnd > *put* 0 into indexNum > *repeat* *get* matchchunk (wikiText, someReg, sNum, eNum) > *if* sNum is not a number > *then* *put* the result into testResult > *-- breakpoint* *exit* *repeat* > *-- regExp bug???* *end* > *if* *if* it is true > *then* *-- this bit not needed (remove for speed)* *-- put char refStart to refEnd of wikiText into someTest* *put* sNum into stripResultArray [indexNum]["sNum"] > *put* eNum into stripResultArray [indexNum]["eNum"] > *add* 1 to indexNum > *--* *-- delete char sNum to eNum of wikiText* *put* pReplaceText into char sNum to eNum of wikiText > *else* *exit* > *repeat* *end* > *if* *end* > *repeat* *return* stripResultArray > *end* text_StripReg I'm sure it could be greatly improved. What I like about the regExp approach is the portability between languages. It also allows the slow building up of quality regExp for specific purposes without constantly changing the underlying code. I'm sure there are faster and leaner approaches though. An extension to merge() along the lines that Mark suggested would cut down on quite a lot of the use-cases i've had over the years - and naturally if would be faster than doing it in script. On Fri, 18 Jan 2019 at 12:53, Mark Waddingham via use-livecode < use-livecode@lists.runrev.com> wrote: > On 2019-01-18 09:01, David Bovill via use-livecode wrote: > > I would love to be able to change the characters that merge uses - > > especially from “[[..]]” to “{{...}}”. > > > > Quite a lot of templating uses curly brackets - and I especially want > > to > > use it for wiki style templates which can’t use square brackets as they > > are > > used for internal links. > > > > Not sure of the most elegant syntax, but we could add some Paramus > > without > > breaking anything. > > The current string scanning which the merge function relies on 5 > codeunits (not characters!): > >- expression start ('[') >- expression finish (']') >- script start ('<') >- script finish ('>') >- script marker ('?') > > With constraints: >- expression start != expression end >- script start != script finish != script marker >- expression start != script start >- expression finish != script finish > > So the easiest / simplest least-likelihood-of-breaking-anything approach > would be to add an optional parameterization to the merge function > consisting of a string between 2 and 5 codeunits: > >- string of 2 codeunits: change expression start / finish, leave > script markers the same >- string of 3 codeunits: change script start / finish / marker, leave > expression markers the same >- string of 4 codeunits: change expression start / finish and script > start / finish, leave script marker the same >- string of 5 codeunits: change all characters > > In all cases it would need to be an error if the above constraints don't > hold. > > For example... > > To get David's wiki-safe option you'd just parameterize by "{}". > > Similarly, merge is not completely XML safe - is a > valid XML directive *and* a value LCS command call (xml version = "1.0") > - so to make that better you could parameterize by "<>|" (<| not being a > valid sequence except in CDATA, which you can elect not to use by entity > escaping chars instead). > > Warmest Regards, > > Mark. > > -- > Mark Waddingham ~ m...@livecode.com ~ http://www.livecode.com/ > LiveCode: Everyone can create apps > > ___ > use-livecode mailing list > use-livecode@lists.runrev.com > Please visit this url to subscribe, unsubscribe and manage your > subscription preferences: > http://lists.runrev.com/mailman/listinfo/use-livecode ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Feature request: merge function!
On 2019-01-18 09:01, David Bovill via use-livecode wrote: I would love to be able to change the characters that merge uses - especially from “[[..]]” to “{{...}}”. Quite a lot of templating uses curly brackets - and I especially want to use it for wiki style templates which can’t use square brackets as they are used for internal links. Not sure of the most elegant syntax, but we could add some Paramus without breaking anything. The current string scanning which the merge function relies on 5 codeunits (not characters!): - expression start ('[') - expression finish (']') - script start ('<') - script finish ('>') - script marker ('?') With constraints: - expression start != expression end - script start != script finish != script marker - expression start != script start - expression finish != script finish So the easiest / simplest least-likelihood-of-breaking-anything approach would be to add an optional parameterization to the merge function consisting of a string between 2 and 5 codeunits: - string of 2 codeunits: change expression start / finish, leave script markers the same - string of 3 codeunits: change script start / finish / marker, leave expression markers the same - string of 4 codeunits: change expression start / finish and script start / finish, leave script marker the same - string of 5 codeunits: change all characters In all cases it would need to be an error if the above constraints don't hold. For example... To get David's wiki-safe option you'd just parameterize by "{}". Similarly, merge is not completely XML safe - is a valid XML directive *and* a value LCS command call (xml version = "1.0") - so to make that better you could parameterize by "<>|" (<| not being a valid sequence except in CDATA, which you can elect not to use by entity escaping chars instead). Warmest Regards, Mark. -- Mark Waddingham ~ m...@livecode.com ~ http://www.livecode.com/ LiveCode: Everyone can create apps ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Feature request: merge function!
eheheheheh let me throw this hack in here and run function davidsMerge pText replace "[[" with "[safe[" in pText replace "]]" with "]safe]" in pText replace "{{" with "[[" in pText replace "}}" with "]]" in pText get the merge of pText replace "[safe[" with "[[" in it replace "]safe]" with "]]" in it return it end davidsMerge Done! On 18/01/2019 08:01, David Bovill via use-livecode wrote: I would love to be able to change the characters that merge uses - especially from “[[..]]” to “{{...}}”. Quite a lot of templating uses curly brackets - and I especially want to use it for wiki style templates which can’t use square brackets as they are used for internal links. Not sure of the most elegant syntax, but we could add some Paramus without breaking anything. ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Feature request: merge function!
I don’t know the setting but might a line or two of preprocessing allow LC to replace the (specific) strings in the template with curly brackets into ones with square brackets for processing? Best, Keith > On 18 Jan 2019, at 09:33, Richard Gaskin via use-livecode > wrote: > > David Bovill wrote: > > > I would love to be able to change the characters that merge uses - > > especially from “[[..]]” to “{{...}}”. > > > > Quite a lot of templating uses curly brackets - and I especially want > > to use it for wiki style templates which can’t use square brackets as > > they are used for internal links. > > Only LC can process the LC-specific code inside of its brackets. With the > current setup it allows LC to be used very gracefully as a preprocessor with > curly-bracket-based systems, so LC processes its stuff without stepping on > directives for other processors. > > -- > Richard Gaskin > Fourth World Systems > Software Design and Development for the Desktop, Mobile, and the Web > > ambassa...@fourthworld.comhttp://www.FourthWorld.com > > ___ > use-livecode mailing list > use-livecode@lists.runrev.com > Please visit this url to subscribe, unsubscribe and manage your subscription > preferences: > http://lists.runrev.com/mailman/listinfo/use-livecode ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Feature request: merge function!
David Bovill wrote: > I would love to be able to change the characters that merge uses - > especially from “[[..]]” to “{{...}}”. > > Quite a lot of templating uses curly brackets - and I especially want > to use it for wiki style templates which can’t use square brackets as > they are used for internal links. Only LC can process the LC-specific code inside of its brackets. With the current setup it allows LC to be used very gracefully as a preprocessor with curly-bracket-based systems, so LC processes its stuff without stepping on directives for other processors. -- Richard Gaskin Fourth World Systems Software Design and Development for the Desktop, Mobile, and the Web ambassa...@fourthworld.comhttp://www.FourthWorld.com ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Feature request: merge function!
I would love to be able to change the characters that merge uses - especially from “[[..]]” to “{{...}}”. Quite a lot of templating uses curly brackets - and I especially want to use it for wiki style templates which can’t use square brackets as they are used for internal links. Not sure of the most elegant syntax, but we could add some Paramus without breaking anything. ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode