mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-20 09:59:09 +02:00
LazUtils: make Deduplicate in DictionaryStringlist a bit more general and improve check for objects.
git-svn-id: trunk@47322 -
This commit is contained in:
parent
9bbe6f00a1
commit
73d61b2750
@ -53,20 +53,27 @@ type
|
|||||||
function IndexOf(const S: string): Integer; override;
|
function IndexOf(const S: string): Integer; override;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure Deduplicate(AStrings: TStringList);
|
function Deduplicate(AStrings: TStrings): Boolean;
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
procedure Deduplicate(AStrings: TStringList);
|
{
|
||||||
|
Removes duplicate strings (case sensitive) from the AStrings object
|
||||||
|
When the AStrings contains objects, the function will return false.
|
||||||
|
}
|
||||||
|
function Deduplicate(AStrings: TStrings): Boolean;
|
||||||
var
|
var
|
||||||
DSL :TDictionaryStringList;
|
i: Integer;
|
||||||
|
DSL: TDictionaryStringList;
|
||||||
begin
|
begin
|
||||||
if AStrings.OwnsObjects then
|
Result := False;
|
||||||
raise Exception.Create('Deduplicate: OwnsObjects in AStrings is not supported.');
|
for i := 0 to AStrings.Count - 1 do
|
||||||
|
if Assigned(AStrings.Objects[i]) then Exit;
|
||||||
DSL := TDictionaryStringList.Create;
|
DSL := TDictionaryStringList.Create;
|
||||||
try
|
try
|
||||||
DSL.Assign(AStrings);
|
DSL.Assign(AStrings);
|
||||||
AStrings.Assign(DSL);
|
AStrings.Assign(DSL);
|
||||||
|
Result := True;
|
||||||
finally
|
finally
|
||||||
DSL.Free;
|
DSL.Free;
|
||||||
end;
|
end;
|
||||||
|
Loading…
Reference in New Issue
Block a user