From 2fb1e0b965e8ab4563dcbf9e59b020f72cc66f84 Mon Sep 17 00:00:00 2001 From: Erich Eckner Date: Wed, 20 Dec 2017 12:01:46 +0100 Subject: besseres und saubereres regex-handling --- tools.pas | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'tools.pas') diff --git a/tools.pas b/tools.pas index 7a62703..7c7f96d 100644 --- a/tools.pas +++ b/tools.pas @@ -9,6 +9,7 @@ uses type tAktualitaet = (aNichtVorhanden,aVeraltet,aAktuell,aWirdErneuert); + tRegexTyp = (rtKein,rtFpc,rtShell); tMyStringListBArray = array[boolean] of tMyStringList; tSummenDatei = record name: string; @@ -43,6 +44,7 @@ procedure testeObBefehlLokal(bef, ordner: string; dateiListe: tMyStringList; lok function extrahiereAlleDateien(woraus: string; dateiListe: tMyStringList): tMyStringList; function unescape(s: string): string; function escape(s,toe: string; ec: char): string; +function escapeStringToRegex(s: string; typ: tRegexTyp; extras: string = ''): string; inline; procedure ersetzeAlleVorkommen(var worin: string; was,wodurch: string); // Routinen für sha512-Prüfsummen @@ -363,6 +365,18 @@ begin end; end; +function escapeStringToRegex(s: string; typ: tRegexTyp; extras: string = ''): string; +begin + case typ of + rtKein: + result:=s; + rtFpc: + result:=escape(s,'\.[+^$'+extras,'\'); + rtShell: + result:=escape(s,'\.[^$'+extras,'\'); + end{of case}; +end; + procedure ersetzeAlleVorkommen(var worin: string; was,wodurch: string); begin while pos(was,worin)>0 do begin -- cgit v1.2.3-54-g00ecf