mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-19 17:49:14 +02:00
rtl/amiga: added minimalistic #?.<ext> and *.<ext> pattern matching to legacy MatchFirst
This commit is contained in:
parent
50572fda8c
commit
cbc8aa63c8
@ -230,11 +230,31 @@ end;
|
|||||||
|
|
||||||
{ helper function used by MatchFirst, all input is expected to be lowercase }
|
{ helper function used by MatchFirst, all input is expected to be lowercase }
|
||||||
function NameMatchesPattern(pattern: AnsiString; filename: AnsiString): boolean;
|
function NameMatchesPattern(pattern: AnsiString; filename: AnsiString): boolean;
|
||||||
|
var
|
||||||
|
ofs: longint;
|
||||||
begin
|
begin
|
||||||
NameMatchesPattern:=(pattern = '*') or (pattern = '#?') or (pattern = filename);
|
NameMatchesPattern:=(pattern = '*') or (pattern = '#?') or (pattern = filename);
|
||||||
if not NameMatchesPattern then
|
if not NameMatchesPattern then
|
||||||
begin
|
begin
|
||||||
// TODO: pattern detection
|
{ handle the simple case of #?.<ext> and *.<ext>, which is one of the most often used }
|
||||||
|
ofs:=Pos('#?',pattern);
|
||||||
|
if (ofs = 1) then
|
||||||
|
begin
|
||||||
|
Delete(pattern,1,length('#?'));
|
||||||
|
ofs:=Pos(pattern,filename);
|
||||||
|
NameMatchesPattern:=(ofs > 0) and ((ofs - 1) = length(filename) - length(pattern));
|
||||||
|
if NameMatchesPattern then
|
||||||
|
exit;
|
||||||
|
end;
|
||||||
|
ofs:=Pos('*',pattern);
|
||||||
|
if (ofs = 1) then
|
||||||
|
begin
|
||||||
|
Delete(pattern,1,length('*'));
|
||||||
|
ofs:=Pos(pattern,filename);
|
||||||
|
NameMatchesPattern:=(ofs > 0) and ((ofs - 1) = length(filename) - length(pattern));
|
||||||
|
if NameMatchesPattern then
|
||||||
|
exit;
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user