summaryrefslogtreecommitdiff
path: root/fpcsrc/packages/fpindexer/src/ireadertxt.pp
blob: cc47e34d4a01844f1e6fe7c7c429aece41086bb3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
{
    This file is part of the Free Component Library (FCL)
    Copyright (c) 2012 by the Free Pascal development team

    Plain text reader
    
    See the file COPYING.FPC, included in this distribution,
    for details about the copyright.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

 **********************************************************************}
unit IReaderTXT;

{$mode objfpc}{$H+}

interface

uses
  Classes, fpIndexer;

type

  { TIReaderTXT }

  TIReaderTXT = class(TCustomFileReader)
  private
  protected
    function AllowedToken(token: string): boolean; override;
  public
    procedure LoadFromStream(FileStream: TStream); override;
  end;

implementation

{ TIReaderTXT }

function TIReaderTXT.AllowedToken(token: string): boolean;
begin
  Result := inherited AllowedToken(token) and (Length(token) > 1);
end;

procedure TIReaderTXT.LoadFromStream(FileStream: TStream);
var
  token: string;
  p: TSearchWordData;
begin
  inherited LoadFromStream(FileStream);
  token := GetToken;
  while token <> '' do
  begin
    if AllowedToken(token) then
    begin
      p.SearchWord := token;
      P.Position:=TokenStartPos;
      p.Context:=GetContext;
      Add(p);
    end;
    token := GetToken;
  end;
end;

initialization
  FileHandlers.RegisterFileReader('Text format', 'txt', TIReaderTXT);

end.