end;
end;
until false;
until false;
end;
// ===========================
// funtion 2
// ===========================
function _matchpattern(apattern, asource: pchar): boolean;
begin
result := true;
while (true) do
begin
case apattern[0] of
#0 : begin
//end of pattern reached.
result := (asource[0] = #0); //true if end of asource.
exit;
end;
'*': begin //match zero or more occurances of any char.
if (apattern[1] = #0) then
begin
//match any number of trailing chars.
result := true;
exit;
end else
inc(apattern);
while (asource[0] <> #0) do
begin
//try to match any substring of asource.
if (_matchpattern(asource, apattern)) then
begin
result := true;
exit;
end;
//continue testing next char...
inc(asource);
end;
end;
'?': begin //match any one char.
if (asource[0] = #0) then
begin
result := false;
exit;
end;
//continue testing next char...
inc(asource);
inc(apattern);
end;
'[': begin //match given set of chars.
if (apattern[1] in [#0,'[',']']) then
begin
//invalid set - so no match.
result := false;
exit;
end;
if (apattern[1] = '^') then
begin
//match for exclusion of given set...
inc(apattern, 2);
result := true;
while (apattern[0] <> ']') do
begin
if (apattern[1] = '-') then
begin
//match char exclusion range.
if (asource[0] >= apattern[0]) and (asource[0] <= apattern[2]) then
begin
//given char failed set exclusion range.
result := false;
break;
end else
inc(apattern, 3);
end else