* Patch from Bart B to improve Slice(). Fixes issue #41068

This commit is contained in:
Michaël Van Canneyt 2024-12-18 20:41:55 +01:00
parent 76e2ee9970
commit 73287c1fa8
2 changed files with 22 additions and 6 deletions

View File

@ -1048,8 +1048,10 @@ type
procedure SaveToStream(Stream: TStream; IgnoreEncoding : Boolean); overload;
procedure SaveToStream(Stream: TStream; AEncoding: TEncoding); overload; virtual;
function Shift : String;
Procedure Slice(fromIndex: integer; aList : TStrings);
Function Slice(fromIndex: integer) : TStrings;
Procedure Slice(fromIndex: integer; aList : TStrings); overload;
Procedure Slice(fromIndex, toIndex: integer; aList : TStrings); overload;
Function Slice(fromIndex: integer) : TStrings; overload;
Function Slice(fromIndex, toIndex: integer) : TStrings; overload;
procedure SetText(TheText: PChar); virtual;
property AlwaysQuote: Boolean read FAlwaysQuote write FAlwaysQuote;
property Capacity: Integer read GetCapacity write SetCapacity;

View File

@ -430,28 +430,42 @@ begin
end;
Procedure TStrings.Slice(fromIndex: integer; aList : TStrings);
Procedure TStrings.Slice(fromIndex, toIndex: integer; aList : TStrings);
var
i: integer;
begin
for i:=fromIndex to Count-1 do
for i:=fromIndex to toIndex do
aList.Add(Self[i]);
end;
Function TStrings.Slice(fromIndex: integer) : TStrings;
Procedure TStrings.Slice(fromIndex: integer; aList : TStrings);
begin
Slice(fromIndex,Count-1,aList);
end;
Function TStrings.Slice(fromIndex, toIndex: integer) : TStrings;
begin
Result:=TStringsClass(Self.ClassType).Create;
try
Slice(FromIndex,Result);
Slice(FromIndex, toIndex,Result);
except
FreeAndNil(Result);
Raise;
end;
end;
Function TStrings.Slice(fromIndex: integer) : TStrings;
begin
Result := Slice(fromIndex,Count-1);
end;
function TStrings.GetName(Index: Integer): string;
Var