From 868c9eceed1355f78fa0271b0d67092a2b448d40 Mon Sep 17 00:00:00 2001 From: Erich Eckner Date: Wed, 23 May 2018 09:15:46 +0200 Subject: lowlevelunit.pas: some new escape functions --- lowlevelunit.pas | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/lowlevelunit.pas b/lowlevelunit.pas index 6a53d08..5a09da9 100644 --- a/lowlevelunit.pas +++ b/lowlevelunit.pas @@ -55,6 +55,7 @@ type tWarnstufe = (wsStreng,wsLasch); tGenauigkeit = (gSingle,gDouble,gExtended); tKantenFilterTyp = (kfTiefpass,kfHochpass); + tRegexTyp = (rtKein,rtFpc,rtShell); operator = (x1,x2: t2x2Extended): boolean; operator = (x1,x2: t2x2Int64): boolean; @@ -158,6 +159,10 @@ procedure splitStrToInt(s: string; out ia: tLongintArray); function vergleicheStrings(s1,s2: string): integer; function pruefSumme(s: string; m: longestOrdinal): longestOrdinal; inline; +function unEscapeCommas(s: string): string; +function escape(s,toe,es: string): string; +function escapeStringToRegex(s: string; typ: tRegexTyp; extras: string = ''): string; inline; + var base64Chars: array[0..63] of char; base64CharsInvers: array[char] of byte; @@ -1323,6 +1328,40 @@ begin result:=((result*256)+ord(s[i])) mod m; end; +function unEscapeCommas(s: string): string; +begin + result:=s; + while pos('\,',result)>0 do + delete(result,pos('\,',result),1); +end; + +function escape(s,toe,es: string): string; +var + i,j: longint; + b: boolean; +begin + result:=''; + for i:=1 to length(s) do begin + b:=false; + for j:=1 to length(toe) do + b:=b or (toe[j]=s[i]); + if b then result:=result+es; + result:=result+s[i]; + 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; + var b: byte; -- cgit v1.2.3-54-g00ecf