⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 2.pas

📁 用Delphi写的Google引擎算法
💻 PAS
字号:

fuction IsDelimiter(aCh : Char; const aDelims : string) : boolean;
var
  i : integer;
begin
  Result := true;
  if (aCh > ' ') then 
    begin
      for i := 1 to length(aDelims) do
        if (aDellims[i] = aCh then Exit;
      Result := false;
    end;
end;

procedure AAParseWords(aText : TStream; const aDelims : string; aAction : TaaWordParseAction);
const
  BufSize = 16 * 1024;
var
  State   : (ScanWord , ScanOther);
  Buffer  : PChar;
  BufPos  : PChar;
  BufLeft : integer;
  Ch      : char;
  StopNow : boolean;
  CharQ   : TaaCharQueue;
begin
  //perpare for the memory allocations
  Buffer := nil;
  CharQ := nil;
  try
    //create a character queue with which to bulid words
    CharQ := TaaCharQueue.Create;
    //allocate a buffer to hold data from the stream
    GetMem(Buffer , BufferSize);
    //force the stream to be read first time through
    BufLeft := 1;
    BufPos := Buffer;
    //we'll start in the scanning delimiter state
    State := ScanOther;
    StopNow := false;
    //continue until there is no more data in the stream
    while (not StopNow) and (BufLeft <> 0) do
      begin
        //advance the buffer variables (reading more data if needed)
        dec(BufLeft);
        if (BufLeft <> 0) then
          inc(BufPos)
        else
          begin
            BufLeft := aText.Read(Buffer^ , BufSize);
            BufPos := Buffer;
          end;
        //get the next character
        Ch := BufPos^;
        //process the character according to the state
        case State of
          ScanWord :
            begin
              if IsDelimiter(Ch , aDelims) then 
                begin
                  aAction(CharQ.AsString , StopNow);
                  State := ScanOther;
                end
              else
                CharQ.Append(Ch);
            end;
          ScanOther :
            begin
              if not IsDelimiter(Ch , aDelims) then
                begin
                  CharQ.Clear;
                  CharQ.Append(Ch);
                  State := ScanWord;
                end;
            end;
        end;
      end;
  finally
    if (Buffer <> nil) then
      FreeMem(Buffer);
    CharQ.Free;
  end;
end;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -