/components/jcf2/Process/Obfuscate/RemoveConsecutiveWhiteSpace.pas

http://github.com/graemeg/lazarus · Pascal · 76 lines · 30 code · 14 blank · 32 comment · 1 complexity · 73f515ec1394c51050a5b02c5dbcdf0c MD5 · raw file

  1. unit RemoveConsecutiveWhiteSpace;
  2. {
  3. AFS 29 Dec 2002
  4. Visitor to remove consecutive whitespace
  5. Obfuscation
  6. }
  7. {(*}
  8. (*------------------------------------------------------------------------------
  9. Delphi Code formatter source code
  10. The Original Code is RemoveConsecutiveWhiteSpace, released May 2003.
  11. The Initial Developer of the Original Code is Anthony Steele.
  12. Portions created by Anthony Steele are Copyright (C) 1999-2008 Anthony Steele.
  13. All Rights Reserved.
  14. Contributor(s): Anthony Steele.
  15. The contents of this file are subject to the Mozilla Public License Version 1.1
  16. (the "License"). you may not use this file except in compliance with the License.
  17. You may obtain a copy of the License at http://www.mozilla.org/NPL/
  18. Software distributed under the License is distributed on an "AS IS" basis,
  19. WITHOUT WARRANTY OF ANY KIND, either express or implied.
  20. See the License for the specific language governing rights and limitations
  21. under the License.
  22. Alternatively, the contents of this file may be used under the terms of
  23. the GNU General Public License Version 2 or later (the "GPL")
  24. See http://www.gnu.org/licenses/gpl.html
  25. ------------------------------------------------------------------------------*)
  26. {*)}
  27. {$I JcfGlobal.inc}
  28. interface
  29. uses SwitchableVisitor;
  30. type
  31. TRemoveConsecutiveWhiteSpace = class(TSwitchableVisitor)
  32. private
  33. fbWhiteSpaceLast: boolean;
  34. protected
  35. function EnabledVisitSourceToken(const pcNode: TObject): Boolean; override;
  36. public
  37. constructor Create; override;
  38. end;
  39. implementation
  40. uses SourceToken, Tokens, FormatFlags, TokenUtils;
  41. constructor TRemoveConsecutiveWhiteSpace.Create;
  42. begin
  43. inherited;
  44. FormatFlags := FormatFlags + [eObfuscate];
  45. end;
  46. function TRemoveConsecutiveWhiteSpace.EnabledVisitSourceToken(const pcNode: TObject): Boolean;
  47. var
  48. lcSourceToken: TSourceToken;
  49. begin
  50. Result := False;
  51. lcSourceToken := TSourceToken(pcNode);
  52. { delete whitespace if the last one was also whitespace }
  53. if (lcSourceToken.TokenType = ttWhiteSpace) and fbWhiteSpaceLast then
  54. BlankToken(lcSourceToken);
  55. fbWhiteSpaceLast := (lcSourceToken.TokenType = ttWhiteSpace);
  56. end;
  57. end.