rejetto forum

Software => HFS ~ HTTP File Server => Bug reports => Topic started by: bacter on October 16, 2009, 09:49:10 AM

Title: error in macro substring
Post by: bacter on October 16, 2009, 09:49:10 AM
There is a error in the substring macro when the include option should include the final delimiter(2,3): instead of including the delimiter, the extracted substring is shortened.

Example:

sample string: abcd[123456]efgh
Macro: {.substring|[|]|abcd[123456]efgh|include=x.}        -> typing error found by mars :D

Results:
no include option: [123456
with include = 0 : 123456
with include = 1 : [123456
with include = 2 : 12345      ------> should be 123456]
with include = 3 : [12345     ------> should be [123456]  

Title: Re: error in macro substring
Post by: Mars on October 16, 2009, 11:26:44 AM
{.substring|[|]abcd[123456]efgh|include=x.}

The macro is incomplete, impossible to reproduce the errors under this shape, missing a  | before abcd ;)

The bug is confirmed, the code must be modified as it to work

Quote
 procedure substring();
  var
    i, j: integer;
    s: string;
    what2inc: integer;
    caseSens: boolean;
  begin
  result:='';

  // input what to be included in the result
  s:=par('include');
  try what2inc:=strToInt(s)
  except // we also support the following values
    if s = 'none' then what2inc:=0
    else if s = 'both' then what2inc:=3
    else if s = '1+2' then what2inc:=3
    else what2inc:=1; // by default we include only the first delimiter
    end;

  caseSens:=isTrue(par('case'));

  // find the delimiters
  s:=macroDequote(par(2));
  if pars[0] = '' then i:=1
  else i:=pos_(caseSens, pars[0], s); // we don' trim this, so you can use blank-space as delimiter
  if i = 0 then exit;
  j:=pos_(caseSens, pars[1], s, i+1);
  if j = 0 then j:=length(s)+1;

  // apply what2inc
  if what2inc and 1 = 0 then
    inc(i, length(pars[0]));
  if what2inc and 2 > 0 then
    INC(j, length(pars[1]));

  // end of the story
  result:=macroQuote(copy(s, i, j-i));
  end; // substring

An error of 'common sense', certainly ;)

Just a little of work in more for rejetto  :D
Title: Re: error in macro substring
Post by: rejetto on October 17, 2009, 02:32:26 PM
ok, thank you mars, fixed in next build ;)
Title: Re: error in macro substring
Post by: bacter on October 19, 2009, 08:40:39 AM
Thanks to mars for his effort to find in the code the bug and propose the solution, as well as having the eye to see my typing error. ;)
And thanks to rejetto for fixing this and all other bugs that are found  ;)
Title: Re: error in macro substring
Post by: rejetto on October 19, 2009, 08:41:03 AM
haha, but you saved me 5 minutes pointing me directly to the  fix
Title: Re: error in macro substring
Post by: SilentPliz on October 19, 2009, 08:43:17 AM
Je vous remercie de voir tant de mercis... si! si!

Merci encore! ;D

Je suis sans merci ! ;D
Title: Re: error in macro substring
Post by: SilentPliz on October 19, 2009, 12:53:40 PM
rejetto wrote:
Quote
Follow members gave a thank to your post:

rejetto
For this post, 1 member gave a thank you!

 ;D ;D ;D ;D excellent! ;D ;D ;D ;D ...








... Merci! :D