mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-14 14:09:20 +02:00
* Fix for bug ID #25464 by Karl-Michael Schindler
git-svn-id: trunk@26747 -
This commit is contained in:
parent
f88b0474c9
commit
249a83ee83
@ -1770,97 +1770,79 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function isWild(inputStr, Wilds: string; ignoreCase: Boolean): Boolean;
|
function isWild(inputStr, Wilds: string; ignoreCase: boolean): boolean;
|
||||||
|
|
||||||
function SearchNext(var Wilds: string): Integer;
|
|
||||||
|
|
||||||
begin
|
|
||||||
Result:=Pos('*', Wilds);
|
|
||||||
if Result>0 then
|
|
||||||
Wilds:=Copy(Wilds,1,Result - 1);
|
|
||||||
end;
|
|
||||||
|
|
||||||
var
|
var
|
||||||
CWild, CinputWord: Integer; { counter for positions }
|
CWild, CinputWord: integer; { counter for positions }
|
||||||
i, LenHelpWilds: Integer;
|
i: integer;
|
||||||
MaxinputWord, MaxWilds: Integer; { Length of inputStr and Wilds }
|
MaxinputWord, MaxWilds: integer; { Length of inputStr and Wilds }
|
||||||
HelpWilds: string;
|
|
||||||
begin
|
begin
|
||||||
if Wilds = inputStr then begin
|
Result:=true;
|
||||||
Result:=True;
|
if Wilds = inputStr then
|
||||||
Exit;
|
Exit;
|
||||||
end;
|
{ delete '**', because '**' = '*' }
|
||||||
repeat { delete '**', because '**' = '*' }
|
i:=Pos('**', Wilds);
|
||||||
|
while i > 0 do
|
||||||
|
begin
|
||||||
|
Delete(Wilds, i, 1);
|
||||||
i:=Pos('**', Wilds);
|
i:=Pos('**', Wilds);
|
||||||
if i > 0 then
|
end;
|
||||||
Wilds:=Copy(Wilds, 1, i - 1) + '*' + Copy(Wilds, i + 2, Maxint);
|
if Wilds = '*' then { for fast end, if Wilds only '*' }
|
||||||
until i = 0;
|
|
||||||
if Wilds = '*' then begin { for fast end, if Wilds only '*' }
|
|
||||||
Result:=True;
|
|
||||||
Exit;
|
Exit;
|
||||||
end;
|
|
||||||
MaxinputWord:=Length(inputStr);
|
MaxinputWord:=Length(inputStr);
|
||||||
MaxWilds:=Length(Wilds);
|
MaxWilds:=Length(Wilds);
|
||||||
if ignoreCase then begin { upcase all letters }
|
if (MaxWilds = 0) or (MaxinputWord = 0) then
|
||||||
|
begin
|
||||||
|
Result:=false;
|
||||||
|
Exit;
|
||||||
|
end;
|
||||||
|
if ignoreCase then { upcase all letters }
|
||||||
|
begin
|
||||||
inputStr:=AnsiUpperCase(inputStr);
|
inputStr:=AnsiUpperCase(inputStr);
|
||||||
Wilds:=AnsiUpperCase(Wilds);
|
Wilds:=AnsiUpperCase(Wilds);
|
||||||
end;
|
end;
|
||||||
if (MaxWilds = 0) or (MaxinputWord = 0) then begin
|
|
||||||
Result:=False;
|
|
||||||
Exit;
|
|
||||||
end;
|
|
||||||
CinputWord:=1;
|
CinputWord:=1;
|
||||||
CWild:=1;
|
CWild:=1;
|
||||||
Result:=True;
|
|
||||||
repeat
|
repeat
|
||||||
if inputStr[CinputWord] = Wilds[CWild] then begin { equal letters }
|
if Wilds[CWild] = '*' then { handling of '*' }
|
||||||
{ goto next letter }
|
begin
|
||||||
inc(CWild);
|
inc(CWild);
|
||||||
inc(CinputWord);
|
while Wilds[CWild] = '?' do { equal to '?' }
|
||||||
Continue;
|
begin
|
||||||
end;
|
{ goto next letter }
|
||||||
if Wilds[CWild] = '?' then begin { equal to '?' }
|
inc(CWild);
|
||||||
{ goto next letter }
|
inc(CinputWord);
|
||||||
inc(CWild);
|
|
||||||
inc(CinputWord);
|
|
||||||
Continue;
|
|
||||||
end;
|
|
||||||
if Wilds[CWild] = '*' then begin { handling of '*' }
|
|
||||||
HelpWilds:=Copy(Wilds, CWild + 1, MaxWilds);
|
|
||||||
i:=SearchNext(HelpWilds);
|
|
||||||
LenHelpWilds:=Length(HelpWilds);
|
|
||||||
if i = 0 then begin
|
|
||||||
{ no '*' in the rest, compare the ends }
|
|
||||||
if HelpWilds = '' then Exit; { '*' is the last letter }
|
|
||||||
{ check the rest for equal Length and no '?' }
|
|
||||||
for i:=0 to LenHelpWilds - 1 do begin
|
|
||||||
if (HelpWilds[LenHelpWilds - i] <> inputStr[MaxinputWord - i]) and
|
|
||||||
(HelpWilds[LenHelpWilds - i]<> '?') then
|
|
||||||
begin
|
|
||||||
Result:=False;
|
|
||||||
Exit;
|
|
||||||
end;
|
|
||||||
end;
|
end;
|
||||||
Exit;
|
{ increase until a match }
|
||||||
end;
|
while (inputStr[CinputWord] <> Wilds[CWild]) and
|
||||||
{ handle all to the next '*' }
|
(CinputWord <= MaxinputWord) do
|
||||||
inc(CWild, 1 + LenHelpWilds);
|
inc(CinputWord);
|
||||||
i:=FindPart(HelpWilds, Copy(inputStr, CinputWord, Maxint));
|
|
||||||
if i= 0 then begin
|
|
||||||
Result:=False;
|
|
||||||
Exit;
|
|
||||||
end;
|
|
||||||
CinputWord:=i + LenHelpWilds;
|
|
||||||
Continue;
|
Continue;
|
||||||
end;
|
end;
|
||||||
Result:=False;
|
if Wilds[CWild] = '?' then { equal to '?' }
|
||||||
|
begin
|
||||||
|
{ goto next letter }
|
||||||
|
inc(CWild);
|
||||||
|
inc(CinputWord);
|
||||||
|
Continue;
|
||||||
|
end;
|
||||||
|
if inputStr[CinputWord] = Wilds[CWild] then { equal letters }
|
||||||
|
begin
|
||||||
|
{ goto next letter }
|
||||||
|
inc(CWild);
|
||||||
|
inc(CinputWord);
|
||||||
|
Continue;
|
||||||
|
end;
|
||||||
|
Result:=false;
|
||||||
Exit;
|
Exit;
|
||||||
until (CinputWord > MaxinputWord) or (CWild > MaxWilds);
|
until (CinputWord > MaxinputWord) or (CWild > MaxWilds);
|
||||||
{ no completed evaluation }
|
{ no completed evaluation }
|
||||||
if CinputWord <= MaxinputWord then Result:=False;
|
if (CinputWord <= MaxinputWord) or
|
||||||
if (CWild <= MaxWilds) and (Wilds[MaxWilds] <> '*') then Result:=False;
|
(CWild <= MaxWilds) then
|
||||||
|
Result:=false;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
function XorString(const Key, Src: ShortString): ShortString;
|
function XorString(const Key, Src: ShortString): ShortString;
|
||||||
var
|
var
|
||||||
i: Integer;
|
i: Integer;
|
||||||
|
Loading…
Reference in New Issue
Block a user