PageRenderTime 19ms CodeModel.GetById 14ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

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