Browse Source

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

Michaël Van Canneyt 7 months ago
parent
commit
73287c1fa8
2 changed files with 22 additions and 6 deletions
  1. 4 2
      rtl/objpas/classes/classesh.inc
  2. 18 4
      rtl/objpas/classes/stringl.inc

+ 4 - 2
rtl/objpas/classes/classesh.inc

@@ -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;

+ 18 - 4
rtl/objpas/classes/stringl.inc

@@ -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