mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-08 23:18:01 +02:00
Move CreateFirstIdentifier, CreateNextIdentifier and MergeSort from LCLProc to LazUtilities.
This commit is contained in:
parent
54ece983b9
commit
ca71aeb4e4
@ -5,7 +5,7 @@ unit PackageLinkIntf;
|
|||||||
interface
|
interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
SysUtils, Classes, System.UITypes,
|
SysUtils, Classes, TypInfo, System.UITypes,
|
||||||
// LazUtils
|
// LazUtils
|
||||||
LazFileUtils,
|
LazFileUtils,
|
||||||
// BuildIntf
|
// BuildIntf
|
||||||
@ -41,6 +41,8 @@ type
|
|||||||
);
|
);
|
||||||
TPkgLinkOrigins = set of TPkgLinkOrigin;
|
TPkgLinkOrigins = set of TPkgLinkOrigin;
|
||||||
|
|
||||||
|
function dbgs(p: TPkgLinkOrigin): string;
|
||||||
|
|
||||||
const
|
const
|
||||||
AllPkgLinkOrigins = [low(TPkgLinkOrigin)..high(TPkgLinkOrigin)];
|
AllPkgLinkOrigins = [low(TPkgLinkOrigin)..high(TPkgLinkOrigin)];
|
||||||
|
|
||||||
@ -134,6 +136,11 @@ var
|
|||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
|
function dbgs(p: TPkgLinkOrigin): string;
|
||||||
|
begin
|
||||||
|
Result:=GetEnumName(TypeInfo(p),ord(p));
|
||||||
|
end;
|
||||||
|
|
||||||
{ TPackageLink }
|
{ TPackageLink }
|
||||||
|
|
||||||
constructor TPackageLink.Create;
|
constructor TPackageLink.Create;
|
||||||
|
@ -34,7 +34,7 @@ uses
|
|||||||
// LCL
|
// LCL
|
||||||
LCLProc, LCLType, LCLIntf, Forms, Menus,
|
LCLProc, LCLType, LCLIntf, Forms, Menus,
|
||||||
// LazUtils
|
// LazUtils
|
||||||
LazLoggerBase, LazTracer, LazMethodList,
|
LazLoggerBase, LazTracer, LazMethodList, LazUtilities,
|
||||||
// IdeIntf
|
// IdeIntf
|
||||||
IDEImagesIntf;
|
IDEImagesIntf;
|
||||||
|
|
||||||
|
@ -20,9 +20,9 @@ interface
|
|||||||
uses
|
uses
|
||||||
Classes, SysUtils,
|
Classes, SysUtils,
|
||||||
// LCL
|
// LCL
|
||||||
LCLProc, LCLType, Menus, ImgList, Graphics,
|
LCLType, Menus, ImgList, Graphics,
|
||||||
// LazUtils
|
// LazUtils
|
||||||
LazLoggerBase, LazTracer,
|
LazLoggerBase, LazTracer, LazUtilities, LazMethodList,
|
||||||
// IdeIntf
|
// IdeIntf
|
||||||
IDECommands;
|
IDECommands;
|
||||||
|
|
||||||
|
@ -17,6 +17,7 @@ uses
|
|||||||
|
|
||||||
type
|
type
|
||||||
TGetSkipCheckByKey = function(AKey: String): Boolean;
|
TGetSkipCheckByKey = function(AKey: String): Boolean;
|
||||||
|
TStringsSortCompare = function(const Item1, Item2: string): Integer;
|
||||||
|
|
||||||
function GetSkipCheckByKey(AKey: String): Boolean;
|
function GetSkipCheckByKey(AKey: String): Boolean;
|
||||||
procedure SetSkipCheckByKeyProc(AProc: TGetSkipCheckByKey);
|
procedure SetSkipCheckByKeyProc(AProc: TGetSkipCheckByKey);
|
||||||
@ -34,6 +35,14 @@ function TruncToInt(e: Extended): integer; inline;
|
|||||||
function TruncToCardinal(e: Extended): cardinal; inline;
|
function TruncToCardinal(e: Extended): cardinal; inline;
|
||||||
function StrToDouble(const s: string): double; inline;
|
function StrToDouble(const s: string): double; inline;
|
||||||
|
|
||||||
|
// identifier
|
||||||
|
function CreateFirstIdentifier(const Identifier: string): string;
|
||||||
|
function CreateNextIdentifier(const Identifier: string): string;
|
||||||
|
|
||||||
|
// sort so that for each i is OnCompare(List[i],List[i+1])<=0
|
||||||
|
procedure MergeSort(List: TFPList; const OnCompare: TListSortCompare); overload;
|
||||||
|
procedure MergeSort(List: TFPList; StartIndex, EndIndex: integer; const OnCompare: TListSortCompare); overload;
|
||||||
|
procedure MergeSort(List: TStrings; const OnCompare: TStringsSortCompare); overload;
|
||||||
{ MergeSortWithLen:
|
{ MergeSortWithLen:
|
||||||
sort ascending, e.g. Compare(List[0],List[1])<0
|
sort ascending, e.g. Compare(List[0],List[1])<0
|
||||||
keeping order (for each i<j and Compare(List[i],List[j])=0) }
|
keeping order (for each i<j and Compare(List[i],List[j])=0) }
|
||||||
@ -137,6 +146,204 @@ begin
|
|||||||
Result:=Double(StrToFloat(s));
|
Result:=Double(StrToFloat(s));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function CreateFirstIdentifier(const Identifier: string): string;
|
||||||
|
// example: Ident59 becomes Ident1
|
||||||
|
var
|
||||||
|
p: Integer;
|
||||||
|
begin
|
||||||
|
p:=length(Identifier);
|
||||||
|
while (p>=1) and (Identifier[p] in ['0'..'9']) do dec(p);
|
||||||
|
Result:=copy(Identifier,1,p)+'1';
|
||||||
|
end;
|
||||||
|
|
||||||
|
function CreateNextIdentifier(const Identifier: string): string;
|
||||||
|
// example: Ident59 becomes Ident60
|
||||||
|
var
|
||||||
|
p: Integer;
|
||||||
|
begin
|
||||||
|
p:=length(Identifier);
|
||||||
|
while (p>=1) and (Identifier[p] in ['0'..'9']) do dec(p);
|
||||||
|
Result:=copy(Identifier,1,p)
|
||||||
|
+IntToStr(1+StrToIntDef(copy(Identifier,p+1,length(Identifier)-p),0));
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure MergeSort(List: TFPList; const OnCompare: TListSortCompare);
|
||||||
|
begin
|
||||||
|
if List=nil then exit;
|
||||||
|
MergeSort(List,0,List.Count-1,OnCompare);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure MergeSort(List: TFPList; StartIndex, EndIndex: integer;
|
||||||
|
const OnCompare: TListSortCompare);
|
||||||
|
// sort so that for each i is OnCompare(List[i],List[i+1])<=0
|
||||||
|
var
|
||||||
|
MergeList: PPointer;
|
||||||
|
|
||||||
|
procedure SmallSort(StartPos, EndPos: PtrInt);
|
||||||
|
// use insertion sort for small lists
|
||||||
|
var
|
||||||
|
i: PtrInt;
|
||||||
|
Best: PtrInt;
|
||||||
|
j: PtrInt;
|
||||||
|
Item: Pointer;
|
||||||
|
begin
|
||||||
|
for i:=StartPos to EndPos-1 do begin
|
||||||
|
Best:=i;
|
||||||
|
for j:=i+1 to EndPos do
|
||||||
|
if OnCompare(List[Best],List[j])>0 then
|
||||||
|
Best:=j;
|
||||||
|
if Best>i then begin
|
||||||
|
Item:=List[i];
|
||||||
|
List[i]:=List[Best];
|
||||||
|
List[Best]:=Item;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure Merge(Pos1, Pos2, Pos3: PtrInt);
|
||||||
|
// merge two sorted arrays
|
||||||
|
// the first array ranges Pos1..Pos2-1, the second ranges Pos2..Pos3
|
||||||
|
var Src1Pos,Src2Pos,DestPos,cmp,a:PtrInt;
|
||||||
|
begin
|
||||||
|
while (Pos3>=Pos2) and (OnCompare(List[Pos2-1],List[Pos3])<=0) do
|
||||||
|
dec(Pos3);
|
||||||
|
if (Pos1>=Pos2) or (Pos2>Pos3) then exit;
|
||||||
|
Src1Pos:=Pos2-1;
|
||||||
|
Src2Pos:=Pos3;
|
||||||
|
DestPos:=Pos3;
|
||||||
|
while (Src2Pos>=Pos2) and (Src1Pos>=Pos1) do begin
|
||||||
|
cmp:=OnCompare(List[Src1Pos],List[Src2Pos]);
|
||||||
|
if cmp>0 then begin
|
||||||
|
MergeList[DestPos]:=List[Src1Pos];
|
||||||
|
dec(Src1Pos);
|
||||||
|
end else begin
|
||||||
|
MergeList[DestPos]:=List[Src2Pos];
|
||||||
|
dec(Src2Pos);
|
||||||
|
end;
|
||||||
|
dec(DestPos);
|
||||||
|
end;
|
||||||
|
while Src2Pos>=Pos2 do begin
|
||||||
|
MergeList[DestPos]:=List[Src2Pos];
|
||||||
|
dec(Src2Pos);
|
||||||
|
dec(DestPos);
|
||||||
|
end;
|
||||||
|
for a:=DestPos+1 to Pos3 do
|
||||||
|
List[a]:=MergeList[a];
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure Sort(StartPos, EndPos: PtrInt);
|
||||||
|
// sort an interval in List. Use MergeList as work space.
|
||||||
|
var
|
||||||
|
mid: integer;
|
||||||
|
begin
|
||||||
|
if EndPos-StartPos<6 then begin
|
||||||
|
SmallSort(StartPos,EndPos);
|
||||||
|
end else begin
|
||||||
|
mid:=(StartPos+EndPos) shr 1;
|
||||||
|
Sort(StartPos,mid);
|
||||||
|
Sort(mid+1,EndPos);
|
||||||
|
Merge(StartPos,mid+1,EndPos);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
var
|
||||||
|
Cnt: Integer;
|
||||||
|
begin
|
||||||
|
if (List=nil) then exit;
|
||||||
|
Cnt:=List.Count;
|
||||||
|
if StartIndex<0 then StartIndex:=0;
|
||||||
|
if EndIndex>=Cnt then EndIndex:=Cnt-1;
|
||||||
|
if StartIndex>=EndIndex then exit;
|
||||||
|
MergeList:=GetMem(List.Count*SizeOf(Pointer));
|
||||||
|
Sort(StartIndex,EndIndex);
|
||||||
|
Freemem(MergeList);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure MergeSort(List: TStrings; const OnCompare: TStringsSortCompare);
|
||||||
|
// sort so that for each i is OnCompare(List[i],List[i+1])<=0
|
||||||
|
var
|
||||||
|
MergeList: PAnsiString;
|
||||||
|
|
||||||
|
procedure SmallSort(StartPos, EndPos: PtrInt);
|
||||||
|
// use insertion sort for small lists
|
||||||
|
var
|
||||||
|
i: PtrInt;
|
||||||
|
Best: PtrInt;
|
||||||
|
j: PtrInt;
|
||||||
|
Item: string;
|
||||||
|
begin
|
||||||
|
for i:=StartPos to EndPos-1 do begin
|
||||||
|
Best:=i;
|
||||||
|
for j:=i+1 to EndPos do
|
||||||
|
if OnCompare(List[Best],List[j])>0 then
|
||||||
|
Best:=j;
|
||||||
|
if Best>i then begin
|
||||||
|
Item:=List[i];
|
||||||
|
List[i]:=List[Best];
|
||||||
|
List[Best]:=Item;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure Merge(Pos1, Pos2, Pos3: PtrInt);
|
||||||
|
// merge two sorted arrays
|
||||||
|
// the first array ranges Pos1..Pos2-1, the second ranges Pos2..Pos3
|
||||||
|
var Src1Pos,Src2Pos,DestPos,cmp,a:integer;
|
||||||
|
begin
|
||||||
|
while (Pos3>=Pos2) and (OnCompare(List[Pos2-1],List[Pos3])<=0) do
|
||||||
|
dec(Pos3);
|
||||||
|
if (Pos1>=Pos2) or (Pos2>Pos3) then exit;
|
||||||
|
Src1Pos:=Pos2-1;
|
||||||
|
Src2Pos:=Pos3;
|
||||||
|
DestPos:=Pos3;
|
||||||
|
while (Src2Pos>=Pos2) and (Src1Pos>=Pos1) do begin
|
||||||
|
cmp:=OnCompare(List[Src1Pos],List[Src2Pos]);
|
||||||
|
if cmp>0 then begin
|
||||||
|
MergeList[DestPos]:=List[Src1Pos];
|
||||||
|
dec(Src1Pos);
|
||||||
|
end else begin
|
||||||
|
MergeList[DestPos]:=List[Src2Pos];
|
||||||
|
dec(Src2Pos);
|
||||||
|
end;
|
||||||
|
dec(DestPos);
|
||||||
|
end;
|
||||||
|
while Src2Pos>=Pos2 do begin
|
||||||
|
MergeList[DestPos]:=List[Src2Pos];
|
||||||
|
dec(Src2Pos);
|
||||||
|
dec(DestPos);
|
||||||
|
end;
|
||||||
|
for a:=DestPos+1 to Pos3 do
|
||||||
|
List[a]:=MergeList[a];
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure Sort(StartPos, EndPos: PtrInt);
|
||||||
|
// sort an interval in List. Use MergeList as work space.
|
||||||
|
var
|
||||||
|
mid: integer;
|
||||||
|
begin
|
||||||
|
if EndPos-StartPos<6 then begin
|
||||||
|
SmallSort(StartPos,EndPos);
|
||||||
|
end else begin
|
||||||
|
mid:=(StartPos+EndPos) shr 1;
|
||||||
|
Sort(StartPos,mid);
|
||||||
|
Sort(mid+1,EndPos);
|
||||||
|
Merge(StartPos,mid+1,EndPos);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
var
|
||||||
|
CurSize: PtrInt;
|
||||||
|
i: PtrInt;
|
||||||
|
begin
|
||||||
|
if (List=nil) or (List.Count<=1) then exit;
|
||||||
|
CurSize:=PtrInt(List.Count)*SizeOf(Pointer);
|
||||||
|
MergeList:=GetMem(CurSize);
|
||||||
|
FillChar(MergeList^,CurSize,0);
|
||||||
|
Sort(0,List.Count-1);
|
||||||
|
for i:=0 to List.Count-1 do MergeList[i]:='';
|
||||||
|
Freemem(MergeList);
|
||||||
|
end;
|
||||||
|
|
||||||
procedure MergeSortWithLen(List: PPointer; ListLength: PtrInt;
|
procedure MergeSortWithLen(List: PPointer; ListLength: PtrInt;
|
||||||
const Compare: TListSortCompare);
|
const Compare: TListSortCompare);
|
||||||
var
|
var
|
||||||
|
@ -33,10 +33,11 @@ interface
|
|||||||
uses
|
uses
|
||||||
Classes, SysUtils, RegExpr,
|
Classes, SysUtils, RegExpr,
|
||||||
// LCL
|
// LCL
|
||||||
LCLProc, Forms, Controls, Dialogs, ClipBrd, StdCtrls, ExtCtrls, Menus,
|
Forms, Controls, Dialogs, ClipBrd, StdCtrls, ExtCtrls, Menus,
|
||||||
ButtonPanel, EditBtn, LCLType,
|
ButtonPanel, EditBtn, LCLType,
|
||||||
// LazUtils
|
// LazUtils
|
||||||
FileUtil, LazFileUtils, LazLoggerBase, LazStringUtils, LazUTF8,
|
FileUtil, LazFileUtils, LazLoggerBase, LazStringUtils, LazUtilities, LazTracer,
|
||||||
|
LazUTF8,
|
||||||
// synedit
|
// synedit
|
||||||
SynEdit, SynHighlighterPas, SynEditAutoComplete, SynEditTypes,
|
SynEdit, SynHighlighterPas, SynEditAutoComplete, SynEditTypes,
|
||||||
// codetools
|
// codetools
|
||||||
|
@ -36,7 +36,7 @@ uses
|
|||||||
// LCL
|
// LCL
|
||||||
Forms, LCLType, LCLProc,
|
Forms, LCLType, LCLProc,
|
||||||
// LazUtils
|
// LazUtils
|
||||||
Laz2_XMLCfg, FileUtil,
|
Laz2_XMLCfg, FileUtil, LazUtilities, LazLoggerBase,
|
||||||
// SynEdit
|
// SynEdit
|
||||||
SynEditKeyCmds, SynPluginTemplateEdit, SynPluginSyncroEdit,
|
SynEditKeyCmds, SynPluginTemplateEdit, SynPluginSyncroEdit,
|
||||||
SynPluginMultiCaret, SynEditMouseCmds,
|
SynPluginMultiCaret, SynEditMouseCmds,
|
||||||
|
202
lcl/lclproc.pas
202
lcl/lclproc.pas
@ -75,15 +75,14 @@ var
|
|||||||
|
|
||||||
function CompareDebugLCLItemInfos(Data1, Data2: Pointer): integer;
|
function CompareDebugLCLItemInfos(Data1, Data2: Pointer): integer;
|
||||||
function CompareItemWithDebugLCLItemInfo(Item, DebugItemInfo: Pointer): integer;
|
function CompareItemWithDebugLCLItemInfo(Item, DebugItemInfo: Pointer): integer;
|
||||||
|
|
||||||
|
|
||||||
type
|
|
||||||
TStringsSortCompare = function(const Item1, Item2: string): Integer;
|
|
||||||
|
|
||||||
// sort so that for each i is OnCompare(List[i],List[i+1])<=0
|
// sort so that for each i is OnCompare(List[i],List[i+1])<=0
|
||||||
procedure MergeSort(List: TFPList; const OnCompare: TListSortCompare); overload; inline;
|
// Deprecated in version 3.99, April 2024.
|
||||||
procedure MergeSort(List: TFPList; StartIndex, EndIndex: integer; const OnCompare: TListSortCompare); overload;
|
procedure MergeSort(List: TFPList;
|
||||||
procedure MergeSort(List: TStrings; const OnCompare: TStringsSortCompare); overload;
|
const OnCompare: TListSortCompare); overload; deprecated 'Use LazUtilities.MergeSort instead';
|
||||||
|
procedure MergeSort(List: TFPList; StartIndex, EndIndex: integer;
|
||||||
|
const OnCompare: TListSortCompare); overload; deprecated 'Use LazUtilities.MergeSort instead';
|
||||||
|
procedure MergeSort(List: TStrings;
|
||||||
|
const OnCompare: TStringsSortCompare); overload; deprecated 'Use LazUtilities.MergeSort instead';
|
||||||
|
|
||||||
function KeyAndShiftStateToKeyString(Key: word; ShiftState: TShiftState): String;
|
function KeyAndShiftStateToKeyString(Key: word; ShiftState: TShiftState): String;
|
||||||
function KeyStringIsIrregular(const s: string): boolean;
|
function KeyStringIsIrregular(const s: string): boolean;
|
||||||
@ -233,8 +232,9 @@ function UTF16CharacterToUnicode(p: PWideChar; out CharLen: integer): Cardinal;
|
|||||||
function UnicodeToUTF16(u: cardinal): UnicodeString; deprecated 'Use LazUTF16.UnicodeToUTF16 instead';
|
function UnicodeToUTF16(u: cardinal): UnicodeString; deprecated 'Use LazUTF16.UnicodeToUTF16 instead';
|
||||||
|
|
||||||
// identifier
|
// identifier
|
||||||
function CreateFirstIdentifier(const Identifier: string): string;
|
// Deprecated in Lazarus 3.99 April 2024.
|
||||||
function CreateNextIdentifier(const Identifier: string): string;
|
function CreateFirstIdentifier(const Identifier: string): string; deprecated 'Use LazUtilities.CreateFirstIdentifier instead';
|
||||||
|
function CreateNextIdentifier(const Identifier: string): string; deprecated 'Use LazUtilities.CreateNextIdentifier instead';
|
||||||
|
|
||||||
// Font
|
// Font
|
||||||
function IsFontNameDefault(const AName: string): boolean; inline;
|
function IsFontNameDefault(const AName: string): boolean; inline;
|
||||||
@ -932,179 +932,18 @@ end;
|
|||||||
|
|
||||||
procedure MergeSort(List: TFPList; const OnCompare: TListSortCompare);
|
procedure MergeSort(List: TFPList; const OnCompare: TListSortCompare);
|
||||||
begin
|
begin
|
||||||
if List=nil then exit;
|
LazUtilities.MergeSort(List, OnCompare);
|
||||||
MergeSort(List,0,List.Count-1,OnCompare);
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure MergeSort(List: TFPList; StartIndex, EndIndex: integer;
|
procedure MergeSort(List: TFPList; StartIndex, EndIndex: integer;
|
||||||
const OnCompare: TListSortCompare);
|
const OnCompare: TListSortCompare);
|
||||||
// sort so that for each i is OnCompare(List[i],List[i+1])<=0
|
|
||||||
var
|
|
||||||
MergeList: PPointer;
|
|
||||||
|
|
||||||
procedure SmallSort(StartPos, EndPos: PtrInt);
|
|
||||||
// use insertion sort for small lists
|
|
||||||
var
|
|
||||||
i: PtrInt;
|
|
||||||
Best: PtrInt;
|
|
||||||
j: PtrInt;
|
|
||||||
Item: Pointer;
|
|
||||||
begin
|
|
||||||
for i:=StartPos to EndPos-1 do begin
|
|
||||||
Best:=i;
|
|
||||||
for j:=i+1 to EndPos do
|
|
||||||
if OnCompare(List[Best],List[j])>0 then
|
|
||||||
Best:=j;
|
|
||||||
if Best>i then begin
|
|
||||||
Item:=List[i];
|
|
||||||
List[i]:=List[Best];
|
|
||||||
List[Best]:=Item;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure Merge(Pos1, Pos2, Pos3: PtrInt);
|
|
||||||
// merge two sorted arrays
|
|
||||||
// the first array ranges Pos1..Pos2-1, the second ranges Pos2..Pos3
|
|
||||||
var Src1Pos,Src2Pos,DestPos,cmp,a:PtrInt;
|
|
||||||
begin
|
|
||||||
while (Pos3>=Pos2) and (OnCompare(List[Pos2-1],List[Pos3])<=0) do
|
|
||||||
dec(Pos3);
|
|
||||||
if (Pos1>=Pos2) or (Pos2>Pos3) then exit;
|
|
||||||
Src1Pos:=Pos2-1;
|
|
||||||
Src2Pos:=Pos3;
|
|
||||||
DestPos:=Pos3;
|
|
||||||
while (Src2Pos>=Pos2) and (Src1Pos>=Pos1) do begin
|
|
||||||
cmp:=OnCompare(List[Src1Pos],List[Src2Pos]);
|
|
||||||
if cmp>0 then begin
|
|
||||||
MergeList[DestPos]:=List[Src1Pos];
|
|
||||||
dec(Src1Pos);
|
|
||||||
end else begin
|
|
||||||
MergeList[DestPos]:=List[Src2Pos];
|
|
||||||
dec(Src2Pos);
|
|
||||||
end;
|
|
||||||
dec(DestPos);
|
|
||||||
end;
|
|
||||||
while Src2Pos>=Pos2 do begin
|
|
||||||
MergeList[DestPos]:=List[Src2Pos];
|
|
||||||
dec(Src2Pos);
|
|
||||||
dec(DestPos);
|
|
||||||
end;
|
|
||||||
for a:=DestPos+1 to Pos3 do
|
|
||||||
List[a]:=MergeList[a];
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure Sort(StartPos, EndPos: PtrInt);
|
|
||||||
// sort an interval in List. Use MergeList as work space.
|
|
||||||
var
|
|
||||||
mid: integer;
|
|
||||||
begin
|
|
||||||
if EndPos-StartPos<6 then begin
|
|
||||||
SmallSort(StartPos,EndPos);
|
|
||||||
end else begin
|
|
||||||
mid:=(StartPos+EndPos) shr 1;
|
|
||||||
Sort(StartPos,mid);
|
|
||||||
Sort(mid+1,EndPos);
|
|
||||||
Merge(StartPos,mid+1,EndPos);
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
var
|
|
||||||
Cnt: Integer;
|
|
||||||
begin
|
begin
|
||||||
if (List=nil) then exit;
|
LazUtilities.MergeSort(List, StartIndex, EndIndex, OnCompare);
|
||||||
Cnt:=List.Count;
|
|
||||||
if StartIndex<0 then StartIndex:=0;
|
|
||||||
if EndIndex>=Cnt then EndIndex:=Cnt-1;
|
|
||||||
if StartIndex>=EndIndex then exit;
|
|
||||||
MergeList:=GetMem(List.Count*SizeOf(Pointer));
|
|
||||||
Sort(StartIndex,EndIndex);
|
|
||||||
Freemem(MergeList);
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure MergeSort(List: TStrings; const OnCompare: TStringsSortCompare);
|
procedure MergeSort(List: TStrings; const OnCompare: TStringsSortCompare);
|
||||||
// sort so that for each i is OnCompare(List[i],List[i+1])<=0
|
|
||||||
var
|
|
||||||
MergeList: PAnsiString;
|
|
||||||
|
|
||||||
procedure SmallSort(StartPos, EndPos: PtrInt);
|
|
||||||
// use insertion sort for small lists
|
|
||||||
var
|
|
||||||
i: PtrInt;
|
|
||||||
Best: PtrInt;
|
|
||||||
j: PtrInt;
|
|
||||||
Item: string;
|
|
||||||
begin
|
|
||||||
for i:=StartPos to EndPos-1 do begin
|
|
||||||
Best:=i;
|
|
||||||
for j:=i+1 to EndPos do
|
|
||||||
if OnCompare(List[Best],List[j])>0 then
|
|
||||||
Best:=j;
|
|
||||||
if Best>i then begin
|
|
||||||
Item:=List[i];
|
|
||||||
List[i]:=List[Best];
|
|
||||||
List[Best]:=Item;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure Merge(Pos1, Pos2, Pos3: PtrInt);
|
|
||||||
// merge two sorted arrays
|
|
||||||
// the first array ranges Pos1..Pos2-1, the second ranges Pos2..Pos3
|
|
||||||
var Src1Pos,Src2Pos,DestPos,cmp,a:integer;
|
|
||||||
begin
|
|
||||||
while (Pos3>=Pos2) and (OnCompare(List[Pos2-1],List[Pos3])<=0) do
|
|
||||||
dec(Pos3);
|
|
||||||
if (Pos1>=Pos2) or (Pos2>Pos3) then exit;
|
|
||||||
Src1Pos:=Pos2-1;
|
|
||||||
Src2Pos:=Pos3;
|
|
||||||
DestPos:=Pos3;
|
|
||||||
while (Src2Pos>=Pos2) and (Src1Pos>=Pos1) do begin
|
|
||||||
cmp:=OnCompare(List[Src1Pos],List[Src2Pos]);
|
|
||||||
if cmp>0 then begin
|
|
||||||
MergeList[DestPos]:=List[Src1Pos];
|
|
||||||
dec(Src1Pos);
|
|
||||||
end else begin
|
|
||||||
MergeList[DestPos]:=List[Src2Pos];
|
|
||||||
dec(Src2Pos);
|
|
||||||
end;
|
|
||||||
dec(DestPos);
|
|
||||||
end;
|
|
||||||
while Src2Pos>=Pos2 do begin
|
|
||||||
MergeList[DestPos]:=List[Src2Pos];
|
|
||||||
dec(Src2Pos);
|
|
||||||
dec(DestPos);
|
|
||||||
end;
|
|
||||||
for a:=DestPos+1 to Pos3 do
|
|
||||||
List[a]:=MergeList[a];
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure Sort(StartPos, EndPos: PtrInt);
|
|
||||||
// sort an interval in List. Use MergeList as work space.
|
|
||||||
var
|
|
||||||
mid: integer;
|
|
||||||
begin
|
|
||||||
if EndPos-StartPos<6 then begin
|
|
||||||
SmallSort(StartPos,EndPos);
|
|
||||||
end else begin
|
|
||||||
mid:=(StartPos+EndPos) shr 1;
|
|
||||||
Sort(StartPos,mid);
|
|
||||||
Sort(mid+1,EndPos);
|
|
||||||
Merge(StartPos,mid+1,EndPos);
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
var
|
|
||||||
CurSize: PtrInt;
|
|
||||||
i: PtrInt;
|
|
||||||
begin
|
begin
|
||||||
if (List=nil) or (List.Count<=1) then exit;
|
LazUtilities.MergeSort(List, OnCompare);
|
||||||
CurSize:=PtrInt(List.Count)*SizeOf(Pointer);
|
|
||||||
MergeList:=GetMem(CurSize);
|
|
||||||
FillChar(MergeList^,CurSize,0);
|
|
||||||
Sort(0,List.Count-1);
|
|
||||||
for i:=0 to List.Count-1 do MergeList[i]:='';
|
|
||||||
Freemem(MergeList);
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
@ -1741,24 +1580,13 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
function CreateFirstIdentifier(const Identifier: string): string;
|
function CreateFirstIdentifier(const Identifier: string): string;
|
||||||
// example: Ident59 becomes Ident1
|
|
||||||
var
|
|
||||||
p: Integer;
|
|
||||||
begin
|
begin
|
||||||
p:=length(Identifier);
|
Result:=LazUtilities.CreateFirstIdentifier(Identifier);
|
||||||
while (p>=1) and (Identifier[p] in ['0'..'9']) do dec(p);
|
|
||||||
Result:=copy(Identifier,1,p)+'1';
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function CreateNextIdentifier(const Identifier: string): string;
|
function CreateNextIdentifier(const Identifier: string): string;
|
||||||
// example: Ident59 becomes Ident60
|
|
||||||
var
|
|
||||||
p: Integer;
|
|
||||||
begin
|
begin
|
||||||
p:=length(Identifier);
|
Result:=LazUtilities.CreateNextIdentifier(Identifier);
|
||||||
while (p>=1) and (Identifier[p] in ['0'..'9']) do dec(p);
|
|
||||||
Result:=copy(Identifier,1,p)
|
|
||||||
+IntToStr(1+StrToIntDef(copy(Identifier,p+1,length(Identifier)-p),0));
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function IsFontNameDefault(const AName: string): boolean;
|
function IsFontNameDefault(const AName: string): boolean;
|
||||||
|
@ -33,11 +33,11 @@ uses
|
|||||||
{$IFDEF Windows}
|
{$IFDEF Windows}
|
||||||
Windows,
|
Windows,
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
Classes, SysUtils, Types, RtlConsts, TypInfo, variants,
|
Classes, SysUtils, Types, RtlConsts, TypInfo, Variants,
|
||||||
// LCL
|
// LCL
|
||||||
LCLProc, LCLStrConsts,
|
LCLStrConsts,
|
||||||
// LazUtils
|
// LazUtils
|
||||||
LazConfigStorage, FPCAdds, DynQueue, LazUTF8, LazLoggerBase;
|
LazConfigStorage, FPCAdds, DynQueue, LazUTF8, LazLoggerBase, LazTracer, LazUtilities;
|
||||||
|
|
||||||
{$DEFINE UseLRS}
|
{$DEFINE UseLRS}
|
||||||
{$DEFINE UseRES}
|
{$DEFINE UseRES}
|
||||||
@ -5856,5 +5856,3 @@ finalization
|
|||||||
|
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -45,11 +45,9 @@ uses
|
|||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
// FPC
|
// FPC
|
||||||
Classes, SysUtils, Contnrs, StrUtils, AVL_Tree, fpmkunit, System.UITypes,
|
Classes, SysUtils, Contnrs, StrUtils, AVL_Tree, fpmkunit, System.UITypes,
|
||||||
// LCL
|
|
||||||
Forms, Dialogs, LCLProc,
|
|
||||||
// LazUtils
|
// LazUtils
|
||||||
FileUtil, LazFileCache, LazLoggerBase, LazUtilities, LazFileUtils, LazUTF8,
|
FileUtil, LazFileCache, LazLoggerBase, LazUtilities, LazFileUtils, LazUTF8,
|
||||||
Laz2_XMLCfg, Laz2_XMLRead, LazStringUtils, AvgLvlTree, FPCAdds,
|
Laz2_XMLCfg, Laz2_XMLRead, LazStringUtils, LazTracer, AvgLvlTree, FPCAdds,
|
||||||
// codetools
|
// codetools
|
||||||
FileProcs, DefineTemplates, CodeToolManager, CodeCache, DirectoryCacher,
|
FileProcs, DefineTemplates, CodeToolManager, CodeCache, DirectoryCacher,
|
||||||
BasicCodeTools, NonPascalCodeTools, SourceChanger,
|
BasicCodeTools, NonPascalCodeTools, SourceChanger,
|
||||||
|
Loading…
Reference in New Issue
Block a user