summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErich Eckner <git@eckner.net>2018-05-23 09:15:46 +0200
committerErich Eckner <git@eckner.net>2018-05-23 09:16:20 +0200
commit868c9eceed1355f78fa0271b0d67092a2b448d40 (patch)
tree94f37407e135570bf844476bc50bd49c5b3d5ec2
parent969e8b38aee700d0d7159dfde0f42098294cca4a (diff)
downloadunits-868c9eceed1355f78fa0271b0d67092a2b448d40.tar.xz
lowlevelunit.pas: some new escape functions
-rw-r--r--lowlevelunit.pas39
1 files changed, 39 insertions, 0 deletions
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;