rejetto forum

¿bug in substring macro?

bacter · 4 · 4522

0 Members and 1 Guest are viewing this topic.

Offline bacter

  • Operator
  • Tireless poster
  • *****
    • Posts: 681
    • View Profile
If you use
{{substring|frompattern|topattern|string}}
and frompattern does not exist, substring returns the full string, and i think in this case it should return void.
your computer has no brain - use your own !


Offline Mars

  • Operator
  • Tireless poster
  • *****
    • Posts: 2059
    • View Profile
here is the delphi code for frompattern

Quote
(frompattern=) i:=max(1, pos(pars[0], s))

if frompattern is not found in string then  pos(pars[0], s) return 0 and max(1, 0) give 1

it is the same thing for toppattern

Quote
(toppattern=) j:=posEx(pars[1], s, i+1);
  if j = 0 then j:=length(s)+1;

If you want to use that you thought of obtaining then here is what you need:

{{if | {{substring|frompattern|topattern|string}} <> {{substring|||string}} |{{\ {{substring|frompattern|topattern|string}} /}} /if }}


Offline bacter

  • Operator
  • Tireless poster
  • *****
    • Posts: 681
    • View Profile
Thank you mars, I have already found a workaround to do what I need.

My question is not what the delphi code does, but what the macro should do in the case if frompattern or topattern are not found!

If rejetto thinks in case that a pattern is not found substring should return the whole string, it's ok. But if he agrees that it would be more logical that when patterns are defined and not found substring should return nothing, then it would be a bug and require some modification like this:

i:=pos(pars[0],s);j=posEx(pars[1],s,max(1,i)+1);
if (i=0 & length(pars[1])>0) | j=0 & length(pars[2])>0) then .. return void string
else i:=max(1,i); if j=0 then j:=length(s+1) .....return string from i to j of s
your computer has no brain - use your own !


Offline rejetto

  • Administrator
  • Tireless poster
  • *****
    • Posts: 13510
    • View Profile