// =========================== // Function 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; |