mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-09-21 17:10:53 +02:00
* Patch from Alexey T. closes #39705
* don't use copy in helper.indexof(). Watch those 0 based indexes.
This commit is contained in:
parent
cb70f9c47d
commit
45bad18019
@ -651,12 +651,19 @@ function TStringHelper.IndexOf(AValue: Char; StartIndex: SizeInt;
|
|||||||
ACount: SizeInt): SizeInt;
|
ACount: SizeInt): SizeInt;
|
||||||
|
|
||||||
Var
|
Var
|
||||||
S : String;
|
CountLim : SizeInt;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
S:=System.Copy(Self,StartIndex+1,ACount);
|
if StartIndex<0 then
|
||||||
Result:=Pos(AValue,S)-1;
|
StartIndex:=0;
|
||||||
if Result<>-1 then
|
CountLim:=System.Length(Self)-StartIndex;
|
||||||
|
if ACount>CountLim then
|
||||||
|
ACount:=CountLim;
|
||||||
|
if ACount<=0 then
|
||||||
|
Exit(-1);
|
||||||
|
// pointer casts are to access self as 0 based index!
|
||||||
|
Result:=IndexChar(PChar(Pointer(self))[StartIndex],ACount,AValue);
|
||||||
|
if Result>=0 then
|
||||||
Result:=Result+StartIndex;
|
Result:=Result+StartIndex;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -665,13 +672,30 @@ function TStringHelper.IndexOf(const AValue: string; StartIndex: SizeInt;
|
|||||||
ACount: SizeInt): SizeInt;
|
ACount: SizeInt): SizeInt;
|
||||||
|
|
||||||
Var
|
Var
|
||||||
S : String;
|
CountLim,NV,Ofs : SizeInt;
|
||||||
|
SP,SE : PChar;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
S:=System.Copy(Self,StartIndex+1,ACount);
|
if StartIndex<0 then
|
||||||
Result:=Pos(AValue,S)-1;
|
StartIndex:=0;
|
||||||
if Result<>-1 then
|
CountLim:=System.Length(Self)-StartIndex;
|
||||||
Result:=Result+StartIndex;
|
if ACount>CountLim then
|
||||||
|
ACount:=CountLim;
|
||||||
|
NV:=System.Length(AValue);
|
||||||
|
if (NV>0) and (ACount>=NV) then
|
||||||
|
begin
|
||||||
|
SP:=PChar(Pointer(Self))+StartIndex;
|
||||||
|
SE:=SP+ACount-NV+1;
|
||||||
|
repeat
|
||||||
|
Ofs:=IndexChar(SP^,SE-SP,PChar(Pointer(AValue))[0]);
|
||||||
|
if Ofs<0 then
|
||||||
|
Break;
|
||||||
|
SP:=SP+Ofs+1;
|
||||||
|
if CompareChar(SP^,PChar(Pointer(AValue))[1],NV-1)=0 then
|
||||||
|
Exit(SP-PChar(Pointer(Self))-1);
|
||||||
|
until false;
|
||||||
|
end;
|
||||||
|
Result:=-1;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TStringHelper.IndexOfUnQuoted(const AValue: string; StartQuote,
|
function TStringHelper.IndexOfUnQuoted(const AValue: string; StartQuote,
|
||||||
|
Loading…
Reference in New Issue
Block a user