From fed2c32e7166a65e87d1afb3faff12075dcd7789 Mon Sep 17 00:00:00 2001 From: Erich Eckner Date: Mon, 27 Jul 2015 14:56:17 +0200 Subject: substitution in mystringlistunit.pas eingebaut --- mystringlistunit.pas | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) (limited to 'mystringlistunit.pas') diff --git a/mystringlistunit.pas b/mystringlistunit.pas index fe6283c..47bc37c 100644 --- a/mystringlistunit.pas +++ b/mystringlistunit.pas @@ -24,8 +24,7 @@ type line: longint; prot: tProtokollant; public - constructor create; overload; - constructor create(protokollant: tProtokollant); overload; + constructor create(protokollant: tProtokollant); procedure loadFromFile(const s: ansiString); override; procedure loadFromGz(const s: ansiString); procedure saveToGz(const s: ansiString); @@ -35,6 +34,7 @@ type procedure rewind; function stillNeed(bez: string): boolean; function unfoldMacros: boolean; + procedure subst(regex,ersatz: string); end; procedure _del(var s: string; p,c: longint); inline; // identisch zu delete(s,p,c) -- lediglich um delete innerhalb von tMyStringlist verfügbar zu haben @@ -77,11 +77,6 @@ end; // tMyStringlist *************************************************************** -constructor tMyStringlist.create; -begin - create(nil); -end; - constructor tMyStringlist.create(protokollant: tProtokollant); begin inherited create; @@ -278,7 +273,7 @@ begin t:=erstesArgument(s,':'); if (length(t)=0) or (t[1]<>'$') then exit; - SchleifenInhalt:=tMyStringlist.create; // Schleifenkörper merken + SchleifenInhalt:=tMyStringlist.create(nil); // Schleifenkörper merken Ebene:=0; while (i0) or (self[i]<>'!Schleifenende')) do begin SchleifenInhalt.Add(self[i]); @@ -403,6 +398,25 @@ begin result:=true; end; +procedure tMyStringlist.subst(regex,ersatz: string); +var + i,cnt: longint; + re: tRegExpr; +begin + re:=tRegExpr.create; + re.expression:='^(.*)('+regex+')(.*)$'; + cnt:=3; + for i:=1 to length(regex) do + if (regex[i]='(') and + ((i=1) or (regex[i-1]<>'\')) then + inc(cnt); + for i:=0 to count-1 do begin + re.exec(self[i]); + self[i]:=re.substitute('$1'+ersatz+'$'+inttostr(cnt)); + end; + re.free; +end; + // allgemeine Funktionen ******************************************************* procedure _del(var s: string; p,c: longint); -- cgit v1.2.3-70-g09d2