* Fix bug ID #31975, LastIndexOf string helper copy&paste error

git-svn-id: trunk@36703 -
This commit is contained in:
michael 2017-07-09 08:43:01 +00:00
parent cf1bd813a8
commit f247a66c90

View File

@ -937,10 +937,34 @@ begin
end;
function TStringHelper.LastIndexOf(const AValue: string; AStartIndex: Integer;
ACount: Integer): Integer;
function TStringHelper.LastIndexOf(const AValue: string; AStartIndex: Integer; ACount: Integer): Integer;
var
I,L,LS,M : Integer;
S : String;
P : PChar;
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;