Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2004-05

Fix To StrUtils.PosExe

2 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Karl Brandt

I noticed that the cited function is not working properly, so i made some (small) changes to fix it.

Here is the fixed version:

Function PosEx(const SubStr, S: string; Offset: Cardinal): Integer;
var i : pchar;
begin
   if (offset<1) or (offset>length(s)) then exit(0);
   i:=strpos(@s[offset],@substr[1]); //Changed here
   if i=nil then
     PosEx:=0
   else
     PosEx:=Succ(i-pchar(s)); // And here
end;

In my program it is working properly, but more tests are wellcome/necessary

Luiz Américo

Reply by email

Marco van de Voort
to Karl Brandt
Show quoted text 15 lines
Here is the fixed version: Function PosEx(const SubStr, S: string; Offset: Cardinal): Integer; var i : pchar; begin if (offset<1) or (offset>length(s)) then exit(0); i:=strpos(@s[offset],@substr[1]); //Changed here if i=nil then PosEx:=0 else PosEx:=Succ(i-pchar(s)); // And here end; In my program it is working properly, but more tests are wellcome/necessary

Committed, thnx the old code (mine actually) was totally flawed (and untested). I added most of the string routines in 1 1/2 hour.

If you find more problems, don't hesitate to report them :-)

Reply by email