mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-18 23:19:12 +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;
|
||||
end;
|
||||
|
||||
procedure Deduplicate(AStrings: TStringList);
|
||||
function Deduplicate(AStrings: TStrings): Boolean;
|
||||
|
||||
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
|
||||
DSL :TDictionaryStringList;
|
||||
i: Integer;
|
||||
DSL: TDictionaryStringList;
|
||||
begin
|
||||
if AStrings.OwnsObjects then
|
||||
raise Exception.Create('Deduplicate: OwnsObjects in AStrings is not supported.');
|
||||
Result := False;
|
||||
for i := 0 to AStrings.Count - 1 do
|
||||
if Assigned(AStrings.Objects[i]) then Exit;
|
||||
DSL := TDictionaryStringList.Create;
|
||||
try
|
||||
DSL.Assign(AStrings);
|
||||
AStrings.Assign(DSL);
|
||||
Result := True;
|
||||
finally
|
||||
DSL.Free;
|
||||
end;
|
||||
|
Loading…
Reference in New Issue
Block a user