From 9d2cf5f16eead95484f918cd24969d12b9d0f64a Mon Sep 17 00:00:00 2001 From: Erich Eckner Date: Fri, 20 May 2016 10:21:39 +0200 Subject: uniq neu in mystringlistunit.pas --- mystringlistunit.pas | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) 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; -- cgit v1.2.3-70-g09d2