summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErich Eckner <git@eckner.net>2016-05-20 10:21:39 +0200
committerErich Eckner <git@eckner.net>2016-05-20 10:21:39 +0200
commit9d2cf5f16eead95484f918cd24969d12b9d0f64a (patch)
tree06010b815cc486ff096fd1323ee7baca93c9247b
parenteffb386323f4259b8436815878a159d16ab9cad8 (diff)
downloadunits-9d2cf5f16eead95484f918cd24969d12b9d0f64a.tar.xz
uniq neu in mystringlistunit.pas
-rw-r--r--mystringlistunit.pas28
1 files changed, 28 insertions, 0 deletions
diff --git a/mystringlistunit.pas b/mystringlistunit.pas
index d37be08..a98e452 100644
--- a/mystringlistunit.pas
+++ b/mystringlistunit.pas
@@ -28,6 +28,7 @@ type
procedure grep(expr: string; invert: boolean = false);
function grepFirst(expr: string): string;
procedure replace(von,nach: string);
+ procedure uniq(c: char);
procedure append(sl: tMyStringList); overload;
function hatZeile(zeile: string): boolean; // invers zu "grep -c"
function eof: boolean;
@@ -228,6 +229,33 @@ begin
self[i]:=re.replace(self[i],nach,true);
end;
+procedure tMyStringlist.uniq(c: char);
+var
+ i: longint;
+ dup: boolean;
+begin
+ case c of
+ '-': // only keep one line for each group
+ for i:=count-1 downto 1 do
+ if self[i]=self[i-1] then
+ delete(i);
+ 'd': begin // only keep duplicate lines, one for each group
+ dup:=false;
+ for i:=count-1 downto 0 do begin
+ if (i>0) and (self[i]=self[i-1]) then begin
+ dup:=true;
+ delete(i);
+ continue;
+ end;
+ if not dup then
+ delete(i);
+ dup:=false;
+ end;
+ end;
+ else fehler('Unbekannte Option '''+c+''' für tMyStringList.uniq!');
+ end{of case};
+end;
+
procedure tMyStringlist.append(sl: tMyStringList);
var
i: longint;