ireadertxt.pp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. {
  2. This file is part of the Free Component Library (FCL)
  3. Copyright (c) 2012 by the Free Pascal development team
  4. Plain text reader
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. **********************************************************************}
  11. unit IReaderTXT;
  12. {$mode objfpc}{$H+}
  13. interface
  14. uses
  15. Classes, fpIndexer;
  16. type
  17. { TIReaderTXT }
  18. TIReaderTXT = class(TCustomFileReader)
  19. private
  20. protected
  21. function AllowedToken(token: UTF8String): boolean; override;
  22. public
  23. procedure LoadFromStream(FileStream: TStream); override;
  24. end;
  25. implementation
  26. { TIReaderTXT }
  27. function TIReaderTXT.AllowedToken(token: UTF8String): boolean;
  28. begin
  29. Result := inherited AllowedToken(token) and (Length(token) > 1);
  30. end;
  31. procedure TIReaderTXT.LoadFromStream(FileStream: TStream);
  32. var
  33. token: UTF8String;
  34. p: TSearchWordData;
  35. begin
  36. inherited LoadFromStream(FileStream);
  37. token := GetToken;
  38. while token <> '' do
  39. begin
  40. if AllowedToken(token) then
  41. begin
  42. p.SearchWord := token;
  43. P.Position:=TokenStartPos;
  44. p.Context:=GetContext;
  45. Add(p);
  46. end;
  47. token := GetToken;
  48. end;
  49. end;
  50. initialization
  51. FileHandlers.RegisterFileReader('Text format', 'txt', TIReaderTXT);
  52. end.