rejetto forum

Software => HFS ~ HTTP File Server => Bug reports => Topic started by: bacter on January 27, 2008, 12:50:44 PM

Title: ¿bug in substring macro?
Post by: bacter 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.
Title: Re: ¿bug in substring macro?
Post by: Mars 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 }}
Title: Re: ¿bug in substring macro?
Post by: bacter 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
Title: Re: ¿bug in substring macro?
Post by: rejetto on January 30, 2008, 03:33:36 PM
fixed in next beta