mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-13 11:39:24 +02:00
* Fix bug ID #31975, LastIndexOf string helper copy&paste error
git-svn-id: trunk@36703 -
This commit is contained in:
parent
cf1bd813a8
commit
f247a66c90
@ -937,10 +937,34 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
function TStringHelper.LastIndexOf(const AValue: string; AStartIndex: Integer;
|
function TStringHelper.LastIndexOf(const AValue: string; AStartIndex: Integer; ACount: Integer): Integer;
|
||||||
ACount: Integer): Integer;
|
|
||||||
|
var
|
||||||
|
I,L,LS,M : Integer;
|
||||||
|
S : String;
|
||||||
|
P : PChar;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
Result:=LastIndexOf(AValue,AStartIndex,AStartIndex+1);
|
Result:=-1;
|
||||||
|
LS:=system.Length(Self);
|
||||||
|
L:=system.Length(AValue);
|
||||||
|
if (L=0) or (L>LS) then
|
||||||
|
Exit;
|
||||||
|
P:=PChar(AValue);
|
||||||
|
S:=Self;
|
||||||
|
I:=AStartIndex+1; // 1 based
|
||||||
|
if (I>LS) then
|
||||||
|
I:=LS;
|
||||||
|
I:=I-L+1;
|
||||||
|
M:=AStartIndex-ACount+1; // 1 based
|
||||||
|
if M<1 then
|
||||||
|
M:=1;
|
||||||
|
while (Result=-1) and (I>=M) do
|
||||||
|
begin
|
||||||
|
if (0=StrLComp(PChar(@S[I]),P,L)) then
|
||||||
|
Result:=I-1;
|
||||||
|
Dec(I);
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user