rejetto forum
Software => HFS ~ HTTP File Server => Bug reports => Topic started 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]
-
{.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
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
-
ok, thank you mars, fixed in next build ;)
-
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 ;)
-
haha, but you saved me 5 minutes pointing me directly to the fix
-
Je vous remercie de voir tant de mercis... si! si!
Merci encore! ;D
Je suis sans merci ! ;D
-
rejetto wrote:
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