|
@@ -641,20 +641,18 @@ begin
|
|
|
end;
|
|
|
|
|
|
|
|
|
+Procedure TStringList.QuickSort(L, R: Integer; CompareFn: TStringListSortCompare);
|
|
|
|
|
|
-Procedure TStringList.QuickSort(L, R: Integer);
|
|
|
-
|
|
|
-Var I,J : Longint;
|
|
|
- Pivot : String;
|
|
|
+Var I,J, Pivot : Longint;
|
|
|
|
|
|
begin
|
|
|
Repeat;
|
|
|
I:=L;
|
|
|
J:=R;
|
|
|
- Pivot:=Flist^[(L+R) div 2].FString;
|
|
|
+ Pivot:=(L+R) div 2;
|
|
|
Repeat
|
|
|
- While AnsiCompareText(Flist^[I].Fstring,Pivot)<0 do Inc(I);
|
|
|
- While AnsiCompareText(Flist^[J].Fstring,Pivot)>0 do Dec(J);
|
|
|
+ While CompareFn(Self, I, Pivot)<0 do Inc(I);
|
|
|
+ While CompareFn(Self, J, Pivot)>0 do Dec(J);
|
|
|
If I<=J then
|
|
|
begin
|
|
|
ExchangeItems(I,J); // No check, indices are correct.
|
|
@@ -662,7 +660,7 @@ begin
|
|
|
Dec(j);
|
|
|
end;
|
|
|
until I>J;
|
|
|
- If L<J then QuickSort(L,J);
|
|
|
+ If L<J then QuickSort(L,J, CompareFn);
|
|
|
L:=I;
|
|
|
Until I>=R;
|
|
|
end;
|
|
@@ -956,20 +954,37 @@ begin
|
|
|
end;
|
|
|
|
|
|
|
|
|
-Procedure TStringList.Sort;
|
|
|
+Procedure TStringList.CustomSort(CompareFn: TStringListSortCompare);
|
|
|
|
|
|
begin
|
|
|
If Not Sorted and (FCount>1) then
|
|
|
begin
|
|
|
Changing;
|
|
|
- QuickSOrt(0,FCount-1);
|
|
|
+ QuickSort(0,FCount-1, CompareFn);
|
|
|
Changed;
|
|
|
end;
|
|
|
end;
|
|
|
|
|
|
+function StringListAnsiCompare(List: TStringList; Index1, Index: Integer): Integer;
|
|
|
+
|
|
|
+begin
|
|
|
+ Result := AnsiCompareText(List.FList^[Index1].FString,
|
|
|
+ List.FList^[Index1].FString);
|
|
|
+end;
|
|
|
+
|
|
|
+Procedure TStringList.Sort;
|
|
|
+
|
|
|
+begin
|
|
|
+ CustomSort(@StringListAnsiCompare);
|
|
|
+end;
|
|
|
+
|
|
|
{
|
|
|
$Log$
|
|
|
- Revision 1.1.2.1 2000-11-22 22:43:34 peter
|
|
|
+ Revision 1.1.2.2 2000-12-03 22:32:27 sg
|
|
|
+ * Applied patch by Markus Kaemmerer:
|
|
|
+ - Added support for TStringList.CustomSort
|
|
|
+
|
|
|
+ Revision 1.1.2.1 2000/11/22 22:43:34 peter
|
|
|
* commatext fixed
|
|
|
|
|
|
Revision 1.1 2000/07/13 06:31:31 michael
|