Author Topic: ¿bug in substring macro?  (Read 2053 times)

0 Members and 1 Guest are viewing this topic.

Offline bacter

  • Operator
  • Tireless poster
  • *****
  • Posts: 682
    • View Profile
¿bug in substring macro?
« on: January 27, 2008, 12:50:44 PM »
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: 1895
    • View Profile
Re: ¿bug in substring macro?
« Reply #1 on: January 27, 2008, 09:27:57 PM »
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: 682
    • View Profile
Re: ¿bug in substring macro?
« Reply #2 on: January 27, 2008, 11:59:45 PM »
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: 12953
    • View Profile
Re: ¿bug in substring macro?
« Reply #3 on: January 30, 2008, 03:33:36 PM »
fixed in next beta