mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-14 09:59:20 +02:00
LazUtils: Masks: simplify TWindowsMaskUtf8.CompileOtherSpecialChars.
Note: code contains debug writeln's, so it will crash if no console is available.
This commit is contained in:
parent
0be73871b5
commit
e76d29f85b
@ -230,6 +230,9 @@ type
|
|||||||
class function CompareUTF8Sequences(const P1,P2: PChar): integer; static;
|
class function CompareUTF8Sequences(const P1,P2: PChar): integer; static;
|
||||||
function intfMatches(aMatchOffset: integer; aMaskIndex: integer): TMaskFailCause; //override;
|
function intfMatches(aMatchOffset: integer; aMaskIndex: integer): TMaskFailCause; //override;
|
||||||
public
|
public
|
||||||
|
|
||||||
|
procedure DumpMaskCompiled;
|
||||||
|
|
||||||
constructor Create(const aMask: String);
|
constructor Create(const aMask: String);
|
||||||
constructor Create(const aMask: String; aCaseSensitive: Boolean);
|
constructor Create(const aMask: String; aCaseSensitive: Boolean);
|
||||||
constructor Create(const aMask: String; aCaseSensitive: Boolean; aOpcodesAllowed: TMaskOpCodes); virtual; overload;
|
constructor Create(const aMask: String; aCaseSensitive: Boolean; aOpcodesAllowed: TMaskOpCodes); virtual; overload;
|
||||||
@ -258,6 +261,7 @@ type
|
|||||||
fWindowsQuirkInUse: TWindowsQuirks;
|
fWindowsQuirkInUse: TWindowsQuirks;
|
||||||
fWindowsMask: String;
|
fWindowsMask: String;
|
||||||
procedure CompileOtherSpecialChars; override;
|
procedure CompileOtherSpecialChars; override;
|
||||||
|
function IsSpecialChar(AChar: Char): Boolean; override;
|
||||||
class procedure SplitFileNameExtension(const aSourceFileName: String;
|
class procedure SplitFileNameExtension(const aSourceFileName: String;
|
||||||
out aFileName: String; out aExtension: String; aIsMask: Boolean=False); static;
|
out aFileName: String; out aExtension: String; aIsMask: Boolean=False); static;
|
||||||
public
|
public
|
||||||
@ -637,7 +641,7 @@ procedure TMaskBase.Add(aValue: TMaskParsedCode);
|
|||||||
var
|
var
|
||||||
v: BYTE;
|
v: BYTE;
|
||||||
begin
|
begin
|
||||||
//writeln('Add: ',aValue);
|
writeln('Add: ',aValue);
|
||||||
v:=BYTE(aValue);
|
v:=BYTE(aValue);
|
||||||
Add(1,@v);
|
Add(1,@v);
|
||||||
end;
|
end;
|
||||||
@ -646,7 +650,7 @@ procedure TMaskBase.IncrementLastCounterBy(aOpcode: TMaskParsedCode; aValue: int
|
|||||||
var
|
var
|
||||||
p: PInteger;
|
p: PInteger;
|
||||||
begin
|
begin
|
||||||
writeln('TMaskBase.IncrementLastCounterBy: aOPcode=',aOpcode,', aValue',aValue);
|
writeln('TMaskBase.IncrementLastCounterBy: aOPcode=',aOpcode,', aValue=',aValue);
|
||||||
fMaskCompiledIndex:=fMaskCompiledIndex-sizeof(aValue);
|
fMaskCompiledIndex:=fMaskCompiledIndex-sizeof(aValue);
|
||||||
if TMaskParsedCode(fMaskCompiled[fMaskCompiledIndex-1])<>aOpcode then
|
if TMaskParsedCode(fMaskCompiled[fMaskCompiledIndex-1])<>aOpcode then
|
||||||
Exception_InternalError();
|
Exception_InternalError();
|
||||||
@ -756,10 +760,7 @@ end;
|
|||||||
|
|
||||||
function TMaskUTF8.IsSpecialChar(AChar: Char): Boolean;
|
function TMaskUTF8.IsSpecialChar(AChar: Char): Boolean;
|
||||||
begin
|
begin
|
||||||
//Result := False
|
Result := False
|
||||||
//********************************
|
|
||||||
Result := AChar = #0;
|
|
||||||
//********************************
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TMaskUTF8.CompileOtherSpecialChars;
|
procedure TMaskUTF8.CompileOtherSpecialChars;
|
||||||
@ -900,14 +901,10 @@ begin
|
|||||||
Exception_InvalidCharMask(fMask[fMaskInd],fMaskInd);
|
Exception_InvalidCharMask(fMask[fMaskInd],fMaskInd);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
writeln('inc(fMaskInd,fCPLength);');
|
|
||||||
inc(fMaskInd,fCPLength);
|
inc(fMaskInd,fCPLength);
|
||||||
writeln('while loop end');
|
|
||||||
end;
|
end;
|
||||||
writeln('After while loop');
|
|
||||||
if fMaskInd>fMaskLimit then
|
if fMaskInd>fMaskLimit then
|
||||||
Exception_MissingCloseChar(']',fMaskLimit);
|
Exception_MissingCloseChar(']',fMaskLimit);
|
||||||
writeln('CompileRange end.');
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TMaskUTF8.GetMask: String;
|
function TMaskUTF8.GetMask: String;
|
||||||
@ -1031,12 +1028,7 @@ begin
|
|||||||
writeln('fMaskCompiled:');
|
writeln('fMaskCompiled:');
|
||||||
writeln('fMaskCompiledLimit=',fMaskCompiledLimit);
|
writeln('fMaskCompiledLimit=',fMaskCompiledLimit);
|
||||||
writeln('fMaskCompiledIndex=',fMaskCompiledIndex);
|
writeln('fMaskCompiledIndex=',fMaskCompiledIndex);
|
||||||
for junk := low(fMaskCompiled) to High(fMaskCompiled) do
|
DumpMaskCompiled;
|
||||||
begin
|
|
||||||
junkbyte := fMaskCompiled[junk];
|
|
||||||
writeln(junk:2,': ',junkbyte:3);
|
|
||||||
end;
|
|
||||||
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
class function TMaskUTF8.CompareUTF8Sequences(const P1, P2: PChar): integer;
|
class function TMaskUTF8.CompareUTF8Sequences(const P1, P2: PChar): integer;
|
||||||
@ -1207,6 +1199,20 @@ begin
|
|||||||
Result:=TMaskFailCause.mfcMatchStringExhausted;
|
Result:=TMaskFailCause.mfcMatchStringExhausted;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TMaskUTF8.DumpMaskCompiled;
|
||||||
|
var
|
||||||
|
junk,H: Integer;
|
||||||
|
junkbyte: Byte;
|
||||||
|
begin
|
||||||
|
H := High(fMaskCompiled);
|
||||||
|
if H > 12 then H := 12;
|
||||||
|
for junk := low(fMaskCompiled) to fMaskCompiledIndex-1 do
|
||||||
|
begin
|
||||||
|
junkbyte := fMaskCompiled[junk];
|
||||||
|
writeln(junk:2,': ',junkbyte:3);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
constructor TMaskUTF8.Create(const aMask: String);
|
constructor TMaskUTF8.Create(const aMask: String);
|
||||||
begin
|
begin
|
||||||
Create(aMask, False, DefaultMaskOpCodes);
|
Create(aMask, False, DefaultMaskOpCodes);
|
||||||
@ -1285,11 +1291,56 @@ procedure TWindowsMaskUTF8.CompileOtherSpecialChars;
|
|||||||
var
|
var
|
||||||
lCharsGroupInsertSize: integer;
|
lCharsGroupInsertSize: integer;
|
||||||
//**************************
|
//**************************
|
||||||
|
OldMin, OldMax, ZeroCount: Integer;
|
||||||
begin
|
begin
|
||||||
inherited CompileOtherSpecialChars;
|
inherited CompileOtherSpecialChars;
|
||||||
writeln('CompileOtherSpecialChars');
|
writeln('CompileOtherSpecialChars');
|
||||||
|
//writeln('fMaskCompiled');
|
||||||
|
//DumpMaskCompiled;
|
||||||
|
|
||||||
|
|
||||||
|
//fMatchMaximumLiteralBytes is incremetend by amount of #0 * 4 (4 bytes since it allows for UTF8)
|
||||||
|
{
|
||||||
|
Add: CharsGroupBegin
|
||||||
|
lCharsGroupInsertSize:=fMaskCompiledIndex;
|
||||||
|
Add(0)
|
||||||
|
Add: AnyCharOrNone
|
||||||
|
Add(1)
|
||||||
|
TMaskBase.IncrementLastCounterBy: aOPcode=AnyCharOrNone, aValue=1 number of zero's -1
|
||||||
|
lCharsGroupInsertSize=1
|
||||||
|
PInteger(@fMaskCompiled[lCharsGroupInsertSize])^:=fMaskCompiledIndex;
|
||||||
|
Add: CharsGroupEnd
|
||||||
|
Inc(fMatchMaximumLiteralBytes,number of zero's *4);
|
||||||
|
Set fMaskInd to last zero (+Count-1)
|
||||||
|
}
|
||||||
|
ZeroCount:=1;
|
||||||
|
while (fMaskInd+ZeroCount<=fMaskLimit) and (fMask[fMaskInd+ZeroCount]=#0) do Inc(ZeroCount);
|
||||||
|
//writeln('Nr of Zero''s: ',ZeroCount);
|
||||||
|
|
||||||
|
Add(TMaskParsedCode.CharsGroupBegin);
|
||||||
|
lCharsGroupInsertSize:=fMaskCompiledIndex;
|
||||||
|
Add(0);
|
||||||
|
Add(TMaskParsedCode.AnyCharOrNone);
|
||||||
|
Add(1);
|
||||||
|
if ZeroCount>1 then
|
||||||
|
IncrementLastCounterBy(TMaskParsedCode.AnyCharOrNone,ZeroCount-1);
|
||||||
|
PInteger(@fMaskCompiled[lCharsGroupInsertSize])^:=fMaskCompiledIndex;
|
||||||
|
Add(TMaskParsedCode.CharsGroupEnd);
|
||||||
|
fLastOC:=TMaskParsedCode.CharsGroupEnd;
|
||||||
|
Inc(fMatchMaximumLiteralBytes,ZeroCount*4);
|
||||||
|
Inc(fMaskInd,ZeroCount-1);
|
||||||
|
write('fMaskInd=',fMaskInd,', fMaskLimit=',fMaskLimit,' fMask[fMaskInd]=');if fMaskInd<=fMaskLimit then writeln('#',Ord(fMask[fMaskInd]),': ',fMask[fMaskInd])else writeln('>>');
|
||||||
|
writeln('CompileOtherSpecialChars end.');
|
||||||
|
{
|
||||||
|
|
||||||
|
EXIT;
|
||||||
|
|
||||||
fLastOC:=TMaskParsedCode.CharsGroupBegin;
|
fLastOC:=TMaskParsedCode.CharsGroupBegin;
|
||||||
Add(TMaskParsedCode.CharsGroupBegin);
|
Add(TMaskParsedCode.CharsGroupBegin);
|
||||||
|
|
||||||
|
//writeln('fMaskCompiled');
|
||||||
|
//DumpMaskCompiled;
|
||||||
|
|
||||||
inc(fMatchMinimumLiteralBytes,1);
|
inc(fMatchMinimumLiteralBytes,1);
|
||||||
if fMatchMaximumLiteralBytes<High(fMatchMaximumLiteralBytes) then
|
if fMatchMaximumLiteralBytes<High(fMatchMaximumLiteralBytes) then
|
||||||
begin //writeln('inc(fMatchMaximumLiteralBytes,4)');
|
begin //writeln('inc(fMatchMaximumLiteralBytes,4)');
|
||||||
@ -1297,7 +1348,10 @@ begin
|
|||||||
//writeln('lCharsGroupInsertSize:=fMaskCompiledIndex;');
|
//writeln('lCharsGroupInsertSize:=fMaskCompiledIndex;');
|
||||||
lCharsGroupInsertSize:=fMaskCompiledIndex;
|
lCharsGroupInsertSize:=fMaskCompiledIndex;
|
||||||
|
|
||||||
|
writeln('Add(0)');
|
||||||
Add(0);
|
Add(0);
|
||||||
|
//writeln('fMaskCompiled after Add(0)');
|
||||||
|
//DumpMaskCompiled;
|
||||||
|
|
||||||
while fMaskInd<=fMaskLimit do begin
|
while fMaskInd<=fMaskLimit do begin
|
||||||
fCPLength:=UTF8CodepointSizeFast(@fMask[fMaskInd]);
|
fCPLength:=UTF8CodepointSizeFast(@fMask[fMaskInd]);
|
||||||
@ -1306,9 +1360,23 @@ begin
|
|||||||
if fLastOC=TMaskParsedCode.AnyCharOrNone then begin
|
if fLastOC=TMaskParsedCode.AnyCharOrNone then begin
|
||||||
// Increment counter
|
// Increment counter
|
||||||
IncrementLastCounterBy(TMaskParsedCode.AnyCharOrNone,1);
|
IncrementLastCounterBy(TMaskParsedCode.AnyCharOrNone,1);
|
||||||
|
|
||||||
|
//writeln('fMaskCompiled');
|
||||||
|
//DumpMaskCompiled;
|
||||||
|
|
||||||
end else begin
|
end else begin
|
||||||
Add(TMaskParsedCode.AnyCharOrNone);
|
Add(TMaskParsedCode.AnyCharOrNone);
|
||||||
|
|
||||||
|
//writeln('fMaskCompiled');
|
||||||
|
//DumpMaskCompiled;
|
||||||
|
|
||||||
|
writeln('Add(1)');
|
||||||
Add(1); // Counter
|
Add(1); // Counter
|
||||||
|
|
||||||
|
//writeln('fMaskCompiled after Add(1)');
|
||||||
|
//DumpMaskCompiled;
|
||||||
|
|
||||||
|
|
||||||
// Discount minimun bytes added at the "CharGroupBegin"
|
// Discount minimun bytes added at the "CharGroupBegin"
|
||||||
// because [?] could be 1 or 0 chars, so minimum is zero
|
// because [?] could be 1 or 0 chars, so minimum is zero
|
||||||
// but the CharsGroupBegin assumes 1 char as all other
|
// but the CharsGroupBegin assumes 1 char as all other
|
||||||
@ -1342,6 +1410,7 @@ begin
|
|||||||
|
|
||||||
|
|
||||||
// Insert the new offset in case of a positive match in CharsGroup
|
// Insert the new offset in case of a positive match in CharsGroup
|
||||||
|
writeln('lCharsGroupInsertSize=',lCharsGroupInsertSize);
|
||||||
PInteger(@fMaskCompiled[lCharsGroupInsertSize])^:=fMaskCompiledIndex;
|
PInteger(@fMaskCompiled[lCharsGroupInsertSize])^:=fMaskCompiledIndex;
|
||||||
Add(TMaskParsedCode.CharsGroupEnd);
|
Add(TMaskParsedCode.CharsGroupEnd);
|
||||||
fLastOC:=TMaskParsedCode.CharsGroupEnd;
|
fLastOC:=TMaskParsedCode.CharsGroupEnd;
|
||||||
@ -1352,17 +1421,36 @@ begin
|
|||||||
end;
|
end;
|
||||||
//fMask ended with #0
|
//fMask ended with #0
|
||||||
if fLastOC<>TMaskParsedCode.CharsGroupEnd then begin
|
if fLastOC<>TMaskParsedCode.CharsGroupEnd then begin
|
||||||
|
writeln('lCharsGroupInsertSize=',lCharsGroupInsertSize);
|
||||||
PInteger(@fMaskCompiled[lCharsGroupInsertSize])^:=fMaskCompiledIndex;
|
PInteger(@fMaskCompiled[lCharsGroupInsertSize])^:=fMaskCompiledIndex;
|
||||||
|
|
||||||
|
//writeln('fMaskCompiled');
|
||||||
|
//DumpMaskCompiled;
|
||||||
|
|
||||||
Add(TMaskParsedCode.CharsGroupEnd);
|
Add(TMaskParsedCode.CharsGroupEnd);
|
||||||
|
|
||||||
|
//writeln('fMaskCompiled');
|
||||||
|
//DumpMaskCompiled;
|
||||||
|
|
||||||
fLastOC:=TMaskParsedCode.CharsGroupEnd;
|
fLastOC:=TMaskParsedCode.CharsGroupEnd;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
Dec(fMaskInd);
|
Dec(fMaskInd);
|
||||||
//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('>>');
|
||||||
|
|
||||||
|
|
||||||
|
//writeln('OldMin: ',OldMin,', fMatchMinimumLiteralBytes:',fMatchMinimumLiteralBytes,', Diff: ',fMatchMinimumLiteralBytes-OldMin);
|
||||||
|
//writeln('OldMax: ',OldMax,', fMatchMaximumLiteralBytes:',fMatchMaximumLiteralBytes,', Diff: ',fMatchMaximumLiteralBytes-OldMax);
|
||||||
|
|
||||||
if fMaskInd>fMaskLimit then
|
if fMaskInd>fMaskLimit then
|
||||||
Exception_MissingCloseChar(']',fMaskLimit);
|
Exception_MissingCloseChar(']',fMaskLimit);
|
||||||
//writeln('CompileOtherSpecialChars end.');
|
writeln('CompileOtherSpecialChars end.');
|
||||||
|
}
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TWindowsMaskUTF8.IsSpecialChar(AChar: Char): Boolean;
|
||||||
|
begin
|
||||||
|
Result := (AChar = #0);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
class procedure TWindowsMaskUTF8.SplitFileNameExtension(
|
class procedure TWindowsMaskUTF8.SplitFileNameExtension(
|
||||||
|
Loading…
Reference in New Issue
Block a user