2个不错的通配符比较函数[2]

[入库:2005年8月18日] [更新:2007年3月24日]

本文简介:选择自 fsxlh 的 blog

             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

本文关键:2个不错的通配符比较函数
  相关方案
Google
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top