mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-17 15:59:13 +02:00
LazUtils: prepare CompileAnyCharOrNone so that if can be re-used in TWindowsMaskUTF8.CompileOtherSpecialChars.
Fix compilation in TWindowsMaskUTF8.CompileOtherSpecialChars Fix off by 1 error on errormessage in CompileAnyCharOrNone. Note: code contains writeln's, so it will crash if no console is available.
This commit is contained in:
parent
36cc485850
commit
ad69e5b56b
@ -225,7 +225,7 @@ type
|
|||||||
procedure CompileRange;
|
procedure CompileRange;
|
||||||
procedure CompileEscapeCharPlusLiteral;
|
procedure CompileEscapeCharPlusLiteral;
|
||||||
procedure CompileSpecialChars;
|
procedure CompileSpecialChars;
|
||||||
procedure CompileAnyCharOrNone;
|
procedure CompileAnyCharOrNone(QChar: Char; BracketsRequired: Boolean);
|
||||||
function GetMask: String; virtual;
|
function GetMask: String; virtual;
|
||||||
procedure SetMask(AValue: String); virtual;
|
procedure SetMask(AValue: String); virtual;
|
||||||
protected
|
protected
|
||||||
@ -815,7 +815,7 @@ var
|
|||||||
begin
|
begin
|
||||||
writeln('CompileRange: fMask[fMaskInd]=',fMask[fMaskInd]);
|
writeln('CompileRange: fMask[fMaskInd]=',fMask[fMaskInd]);
|
||||||
if (mocAnyCharOrNone in fMaskOpcodesAllowed) and (fMaskInd<fMaskLimit) and (fMask[fMaskInd+1]='?') then begin
|
if (mocAnyCharOrNone in fMaskOpcodesAllowed) and (fMaskInd<fMaskLimit) and (fMask[fMaskInd+1]='?') then begin
|
||||||
CompileAnyCharOrNone;
|
CompileAnyCharOrNone('?', True);
|
||||||
end else begin//not AnyCharOrNone
|
end else begin//not AnyCharOrNone
|
||||||
fLastOC:=TMaskParsedCode.CharsGroupBegin;
|
fLastOC:=TMaskParsedCode.CharsGroupBegin;
|
||||||
Add(TMaskParsedCode.CharsGroupBegin);
|
Add(TMaskParsedCode.CharsGroupBegin);
|
||||||
@ -1001,7 +1001,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TMaskUTF8.CompileAnyCharOrNone;
|
procedure TMaskUTF8.CompileAnyCharOrNone(QChar: Char; BracketsRequired: Boolean);
|
||||||
var
|
var
|
||||||
QCount, lCharsGroupInsertSize: Integer;
|
QCount, lCharsGroupInsertSize: Integer;
|
||||||
begin
|
begin
|
||||||
@ -1022,33 +1022,31 @@ begin
|
|||||||
|
|
||||||
|
|
||||||
{$IFDEF debug_anycharornone}
|
{$IFDEF debug_anycharornone}
|
||||||
if fMask[fMaskInd]<>'[' then
|
if BracketsRequired and (fMask[fMaskInd]<>'[') then
|
||||||
Exception_InternalError();
|
Exception_InternalError();
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
|
if BracketsRequired then
|
||||||
Inc(fMaskInd); //consume the '['
|
Inc(fMaskInd); //consume the '['
|
||||||
|
|
||||||
|
|
||||||
{$IFDEF debug_anycharornone}
|
{$IFDEF debug_anycharornone}
|
||||||
if fMask[fMaskInd]<>'?' then
|
if fMask[fMaskInd]<>QChar then
|
||||||
Exception_InternalError();
|
Exception_InternalError();
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
|
|
||||||
QCount:=1;
|
QCount:=1;
|
||||||
while (fMaskInd+QCount<=fMaskLimit) and (fMask[fMaskInd+QCount]='?') do Inc(QCount);
|
while (fMaskInd+QCount<=fMaskLimit) and (fMask[fMaskInd+QCount]=QChar) do Inc(QCount);
|
||||||
writeln('CompileAnyCharOrNone: Nr of AnyCharOrNone-tokens: ',QCount);
|
writeln('CompileAnyCharOrNone: Nr of AnyCharOrNone-tokens: ',QCount);
|
||||||
if (fMaskInd+QCount>fMaskLimit) then writeln('(fMaskInd+QCount>=fMaskLimit): ',fMaskInd+QCount,'>',fMaskLimit);
|
|
||||||
|
|
||||||
if (fMaskInd+QCount>fMaskLimit) then
|
if (fMaskInd+QCount>fMaskLimit) then writeln('(fMaskInd+QCount>fMaskLimit): ',fMaskInd+QCount,'>',fMaskLimit);
|
||||||
Exception_MissingCloseChar(']',fMaskInd+QCount+1);
|
//is Last found QChar also last character of the mask, while we expect a closing ']'?
|
||||||
|
if BracketsRequired and (fMaskInd+QCount>fMaskLimit) then
|
||||||
|
Exception_MissingCloseChar(']',fMaskInd+QCount-1);
|
||||||
|
|
||||||
if not (fMask[fMaskInd+QCount]=']') then writeln('fMask[fMaskInd+QCount+1]: expected ], found: ',fMask[fMaskInd+QCount+1]);
|
if not (fMask[fMaskInd+QCount]=']') then writeln('fMask[fMaskInd+QCount]: expected ], found: ',fMask[fMaskInd+QCount]);
|
||||||
|
|
||||||
if not (fMask[fMaskInd+QCount]=']') then
|
if BracketsRequired and not (fMask[fMaskInd+QCount]=']') then
|
||||||
Exception_InvalidCharMask(fMask[fMaskInd+QCount+1],fMaskInd+QCount+1);
|
Exception_InvalidCharMask(fMask[fMaskInd+QCount],fMaskInd+QCount);
|
||||||
|
|
||||||
if QCount=0 then
|
|
||||||
Exception_IncompleteMask;
|
|
||||||
|
|
||||||
Add(TMaskParsedCode.CharsGroupBegin);
|
Add(TMaskParsedCode.CharsGroupBegin);
|
||||||
lCharsGroupInsertSize:=fMaskCompiledIndex;
|
lCharsGroupInsertSize:=fMaskCompiledIndex;
|
||||||
@ -1061,7 +1059,10 @@ begin
|
|||||||
Add(TMaskParsedCode.CharsGroupEnd);
|
Add(TMaskParsedCode.CharsGroupEnd);
|
||||||
fLastOC:=TMaskParsedCode.CharsGroupEnd;
|
fLastOC:=TMaskParsedCode.CharsGroupEnd;
|
||||||
Inc(fMatchMaximumLiteralBytes,QCount*4);
|
Inc(fMatchMaximumLiteralBytes,QCount*4);
|
||||||
Inc(fMaskInd,QCount); //go to ending ']'
|
if BracketsRequired then
|
||||||
|
Inc(fMaskInd,QCount) //go to ending ']'
|
||||||
|
else
|
||||||
|
Inc(fMaskInd,QCount-1); //go to last found QChar
|
||||||
|
|
||||||
{$IFDEF debug_anycharornone}
|
{$IFDEF debug_anycharornone}
|
||||||
write('fMaskInd=',fMaskInd,', fMaskLimit=',fMaskLimit,' fMask[fMaskInd]=');if fMaskInd<=fMaskLimit then writeln('#',Ord(fMask[fMaskInd]),': ',fMask[fMaskInd])else writeln('>>');
|
write('fMaskInd=',fMaskInd,', fMaskLimit=',fMaskLimit,' fMask[fMaskInd]=');if fMaskInd<=fMaskLimit then writeln('#',Ord(fMask[fMaskInd]),': ',fMask[fMaskInd])else writeln('>>');
|
||||||
@ -1380,7 +1381,7 @@ var
|
|||||||
ZeroCount: Integer;
|
ZeroCount: Integer;
|
||||||
begin
|
begin
|
||||||
inherited CompileOtherSpecialChars;
|
inherited CompileOtherSpecialChars;
|
||||||
if (fMask[fMaskInd]=#0) and not (wqFileNamEnd in self.fWindowsQuirkInUse) then
|
if (fMask[fMaskInd]=#0) and not (wqFileNameEnd in self.fWindowsQuirkInUse) then
|
||||||
Exception_InternalError;
|
Exception_InternalError;
|
||||||
ZeroCount:=1;
|
ZeroCount:=1;
|
||||||
while (fMaskInd+ZeroCount<=fMaskLimit) and (fMask[fMaskInd+ZeroCount]=#0) do Inc(ZeroCount);
|
while (fMaskInd+ZeroCount<=fMaskLimit) and (fMask[fMaskInd+ZeroCount]=#0) do Inc(ZeroCount);
|
||||||
|
Loading…
Reference in New Issue
Block a user