mirror of
https://github.com/doublecmd/doublecmd.git
synced 2026-06-21 09:58:13 +00:00
ADD: RegExpr validation for UTF8 encoded files in TfrmFindDlg.InvalidRegExpr method (#386)
* FIX: Trimming string length after calling pcre2_get_error_message * ADD: Added ExecRegExpr function to uregexpru unit * FIX: Added regexpr validation for UTF8 encoded files in TfrmFindDlg.InvalidRegExpr method
This commit is contained in:
parent
cfb35ac986
commit
988ece57d0
2 changed files with 24 additions and 2 deletions
|
|
@ -2721,8 +2721,11 @@ begin
|
|||
begin
|
||||
sMsg:= cmbFindText.Text;
|
||||
sEncoding:= NormalizeEncoding(cmbEncoding.Text);
|
||||
if sEncoding = EncodingDefault then sEncoding:= GetDefaultTextEncoding;
|
||||
// Use correct RegExp engine
|
||||
if SingleByteEncoding(sEncoding) then
|
||||
if TRegExprU.Available and (sEncoding = EncodingUTF8) then
|
||||
uRegExprU.ExecRegExpr(sMsg, '')
|
||||
else if SingleByteEncoding(sEncoding) then
|
||||
uRegExprA.ExecRegExpr(sMsg, '')
|
||||
else if (sEncoding = EncodingUTF16LE) then
|
||||
uRegExprW.ExecRegExpr(CeUtf8ToUtf16(sMsg), '');
|
||||
|
|
|
|||
|
|
@ -64,6 +64,8 @@ type
|
|||
property MatchLen [Idx : integer] : PtrInt read GetMatchLen;
|
||||
end;
|
||||
|
||||
function ExecRegExpr(const ARegExpr, AInputStr: String): Boolean;
|
||||
|
||||
implementation
|
||||
|
||||
uses
|
||||
|
|
@ -140,6 +142,7 @@ var
|
|||
error: PAnsiChar;
|
||||
errornumber: cint;
|
||||
erroroffset: cint;
|
||||
len: cint;
|
||||
begin
|
||||
FExpression:= AValue;
|
||||
|
||||
|
|
@ -150,7 +153,9 @@ begin
|
|||
FMatch := pcre2_match_data_create_from_pattern(FCode, nil)
|
||||
else begin
|
||||
SetLength(Message, MAX_PATH + 1);
|
||||
pcre2_get_error_message(errornumber, PAnsiChar(Message), MAX_PATH);
|
||||
len := pcre2_get_error_message(errornumber, PAnsiChar(Message), MAX_PATH);
|
||||
if len < 0 then len := Length(PAnsiChar(Message)); // PCRE2_ERROR_NOMEMORY
|
||||
SetLength(Message, len);
|
||||
raise Exception.Create(Message);
|
||||
end;
|
||||
end
|
||||
|
|
@ -286,6 +291,20 @@ begin
|
|||
Result := res >= 0;
|
||||
end;
|
||||
|
||||
function ExecRegExpr(const ARegExpr, AInputStr: String): Boolean;
|
||||
var
|
||||
r: TRegExprU;
|
||||
begin
|
||||
r := TRegExprU.Create;
|
||||
try
|
||||
r.Expression := ARegExpr;
|
||||
r.SetInputString(PChar(AInputStr), Length(AInputStr));
|
||||
Result := r.Exec(1);
|
||||
finally
|
||||
r.Free;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure Initialize;
|
||||
var
|
||||
Where: IntPtr;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue