mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-11 12:25:59 +02:00
parent
32c307e9ce
commit
f575eafa1e
@ -710,7 +710,7 @@ const
|
|||||||
|
|
||||||
function StrPCopy (Dest: PRegExprChar; const Source: RegExprString): PRegExprChar;
|
function StrPCopy (Dest: PRegExprChar; const Source: RegExprString): PRegExprChar;
|
||||||
var
|
var
|
||||||
i, Len : PtrInt;
|
Len : PtrInt;
|
||||||
begin
|
begin
|
||||||
Len := length (Source); //###0.932
|
Len := length (Source); //###0.932
|
||||||
if Len>0 then
|
if Len>0 then
|
||||||
@ -721,55 +721,63 @@ function StrPCopy (Dest: PRegExprChar; const Source: RegExprString): PRegExprCha
|
|||||||
--------------------------------------------------------------}
|
--------------------------------------------------------------}
|
||||||
|
|
||||||
function StrLCopy (Dest, Source: PRegExprChar; MaxLen: PtrUInt): PRegExprChar;
|
function StrLCopy (Dest, Source: PRegExprChar; MaxLen: PtrUInt): PRegExprChar;
|
||||||
var i: PtrInt;
|
|
||||||
begin
|
begin
|
||||||
if MaxLen>0 then
|
if MaxLen>0 then
|
||||||
move(Source[0],Dest[0],MaxLen*sizeof(ReChar));
|
move(Source[0],Dest[0],MaxLen*sizeof(ReChar));
|
||||||
Result := Dest;
|
Result := Dest;
|
||||||
end; { of function StrLCopy
|
end; { of function StrLCopy
|
||||||
--------------------------------------------------------------}
|
--------------------------------------------------------------}
|
||||||
|
|
||||||
function StrLen (Str: PRegExprChar): PtrUInt;
|
function StrLen (Str: PRegExprChar): PtrUInt;
|
||||||
begin
|
|
||||||
|
begin
|
||||||
Result:=0;
|
Result:=0;
|
||||||
while Str [result] <> #0
|
while Str [result] <> #0 do
|
||||||
do Inc (Result);
|
Inc (Result);
|
||||||
end; { of function StrLen
|
end; { of function StrLen
|
||||||
--------------------------------------------------------------}
|
--------------------------------------------------------------}
|
||||||
|
|
||||||
function StrPos (Str1, Str2: PRegExprChar): PRegExprChar;
|
function StrPos (Str1, Str2: PRegExprChar): PRegExprChar;
|
||||||
var n: PtrInt;
|
|
||||||
begin
|
var
|
||||||
|
n: PtrInt;
|
||||||
|
|
||||||
|
begin
|
||||||
Result := nil;
|
Result := nil;
|
||||||
n := Pos (RegExprString (Str2), RegExprString (Str1));
|
n := Pos (RegExprString (Str2), RegExprString (Str1));
|
||||||
if n = 0
|
if n = 0 then
|
||||||
then EXIT;
|
EXIT;
|
||||||
Result := Str1 + n - 1;
|
Result := Str1 + n - 1;
|
||||||
end; { of function StrPos
|
end; { of function StrPos
|
||||||
--------------------------------------------------------------}
|
--------------------------------------------------------------}
|
||||||
|
|
||||||
function StrLComp (Str1, Str2: PRegExprChar; MaxLen: PtrUInt): PtrInt;
|
function StrLComp (Str1, Str2: PRegExprChar; MaxLen: PtrUInt): PtrInt;
|
||||||
var S1, S2: RegExprString;
|
|
||||||
begin
|
var
|
||||||
|
S1, S2: RegExprString;
|
||||||
|
|
||||||
|
begin
|
||||||
S1 := Str1;
|
S1 := Str1;
|
||||||
S2 := Str2;
|
S2 := Str2;
|
||||||
if Copy (S1, 1, MaxLen) > Copy (S2, 1, MaxLen)
|
if Copy (S1, 1, MaxLen) > Copy (S2, 1, MaxLen) then
|
||||||
then Result := 1
|
Result := 1
|
||||||
else
|
else if Copy (S1, 1, MaxLen) < Copy (S2, 1, MaxLen) then
|
||||||
if Copy (S1, 1, MaxLen) < Copy (S2, 1, MaxLen)
|
Result := -1
|
||||||
then Result := -1
|
else
|
||||||
else Result := 0;
|
Result := 0;
|
||||||
end; { function StrLComp
|
end; { function StrLComp
|
||||||
--------------------------------------------------------------}
|
--------------------------------------------------------------}
|
||||||
|
|
||||||
function StrScan (Str: PRegExprChar; Chr: WideChar): PRegExprChar;
|
function StrScan (Str: PRegExprChar; Chr: WideChar): PRegExprChar;
|
||||||
begin
|
|
||||||
|
begin
|
||||||
Result := nil;
|
Result := nil;
|
||||||
while (Str^ <> #0) and (Str^ <> Chr)
|
while (Str^ <> #0) and (Str^ <> Chr) do
|
||||||
do Inc (Str);
|
Inc (Str);
|
||||||
if (Str^ <> #0)
|
if (Str^ <> #0) then
|
||||||
then Result := Str;
|
Result := Str;
|
||||||
end; { of function StrScan
|
end; { of function StrScan
|
||||||
--------------------------------------------------------------}
|
--------------------------------------------------------------}
|
||||||
|
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
@ -780,39 +788,43 @@ function StrScan (Str: PRegExprChar; Chr: WideChar): PRegExprChar;
|
|||||||
{=============================================================}
|
{=============================================================}
|
||||||
|
|
||||||
function ExecRegExpr (const ARegExpr, AInputStr : RegExprString) : boolean;
|
function ExecRegExpr (const ARegExpr, AInputStr : RegExprString) : boolean;
|
||||||
var r : TRegExpr;
|
|
||||||
begin
|
begin
|
||||||
r := TRegExpr.Create;
|
With TRegExpr.Create do
|
||||||
try
|
try
|
||||||
r.Expression := ARegExpr;
|
Expression := ARegExpr;
|
||||||
Result := r.Exec (AInputStr);
|
Result := Exec (AInputStr);
|
||||||
finally r.Free;
|
finally
|
||||||
end;
|
Free;
|
||||||
|
end;
|
||||||
end; { of function ExecRegExpr
|
end; { of function ExecRegExpr
|
||||||
--------------------------------------------------------------}
|
--------------------------------------------------------------}
|
||||||
|
|
||||||
procedure SplitRegExpr (const ARegExpr, AInputStr : RegExprString; APieces : TStrings);
|
procedure SplitRegExpr (const ARegExpr, AInputStr : RegExprString; APieces : TStrings);
|
||||||
var r : TRegExpr;
|
|
||||||
begin
|
begin
|
||||||
APieces.Clear;
|
APieces.Clear;
|
||||||
r := TRegExpr.Create;
|
With TRegExpr.Create do
|
||||||
try
|
try
|
||||||
r.Expression := ARegExpr;
|
Expression := ARegExpr;
|
||||||
r.Split (AInputStr, APieces);
|
Split (AInputStr, APieces);
|
||||||
finally r.Free;
|
finally
|
||||||
|
Free;
|
||||||
end;
|
end;
|
||||||
end; { of procedure SplitRegExpr
|
end; { of procedure SplitRegExpr
|
||||||
--------------------------------------------------------------}
|
--------------------------------------------------------------}
|
||||||
|
|
||||||
function ReplaceRegExpr (const ARegExpr, AInputStr, AReplaceStr : RegExprString;
|
function ReplaceRegExpr (const ARegExpr, AInputStr, AReplaceStr : RegExprString;
|
||||||
AUseSubstitution : boolean{$IFDEF DefParam}= False{$ENDIF}) : RegExprString;
|
AUseSubstitution : boolean{$IFDEF DefParam}= False{$ENDIF}) : RegExprString;
|
||||||
begin
|
begin
|
||||||
with TRegExpr.Create do try
|
with TRegExpr.Create do
|
||||||
Expression := ARegExpr;
|
try
|
||||||
Result := Replace (AInputStr, AReplaceStr, AUseSubstitution);
|
Expression := ARegExpr;
|
||||||
finally Free;
|
Result := Replace (AInputStr, AReplaceStr, AUseSubstitution);
|
||||||
end;
|
finally
|
||||||
end; { of function ReplaceRegExpr
|
Free;
|
||||||
|
end;
|
||||||
|
end; { of function ReplaceRegExpr
|
||||||
--------------------------------------------------------------}
|
--------------------------------------------------------------}
|
||||||
|
|
||||||
function QuoteRegExprMetaChars (const AStr : RegExprString) : RegExprString;
|
function QuoteRegExprMetaChars (const AStr : RegExprString) : RegExprString;
|
||||||
@ -823,7 +835,7 @@ function QuoteRegExprMetaChars (const AStr : RegExprString) : RegExprString;
|
|||||||
// !Any changes in META array must be synchronized with this set.
|
// !Any changes in META array must be synchronized with this set.
|
||||||
var
|
var
|
||||||
i, i0, Len : PtrInt;
|
i, i0, Len : PtrInt;
|
||||||
begin
|
begin
|
||||||
Result := '';
|
Result := '';
|
||||||
Len := length (AStr);
|
Len := length (AStr);
|
||||||
i := 1;
|
i := 1;
|
||||||
@ -837,7 +849,7 @@ function QuoteRegExprMetaChars (const AStr : RegExprString) : RegExprString;
|
|||||||
inc (i);
|
inc (i);
|
||||||
end;
|
end;
|
||||||
Result := Result + System.Copy (AStr, i0, MaxInt); // Tail
|
Result := Result + System.Copy (AStr, i0, MaxInt); // Tail
|
||||||
end; { of function QuoteRegExprMetaChars
|
end; { of function QuoteRegExprMetaChars
|
||||||
--------------------------------------------------------------}
|
--------------------------------------------------------------}
|
||||||
|
|
||||||
function RegExprSubExpressions (const ARegExpr : string;
|
function RegExprSubExpressions (const ARegExpr : string;
|
||||||
|
Loading…
Reference in New Issue
Block a user