source: branches/0.8-stable/lib/LineTypeParser.h @ 1199

Last change on this file since 1199 was 978, checked in by Peter Johansson, 11 years ago

refs #429. Convert copyright statements to UTF-8

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.4 KB
Line 
1#ifndef _theplu_svndigest_line_type_parser_
2#define _theplu_svndigest_line_type_parser_
3
4// $Id: LineTypeParser.h 978 2009-12-12 20:09:41Z peter $
5
6/*
7  Copyright (C) 2006, 2007, 2008 Jari Häkkinen, Peter Johansson
8  Copyright (C) 2009 Peter Johansson
9
10  This file is part of svndigest, http://dev.thep.lu.se/svndigest
11
12  svndigest is free software; you can redistribute it and/or modify it
13  under the terms of the GNU General Public License as published by
14  the Free Software Foundation; either version 3 of the License, or
15  (at your option) any later version.
16
17  svndigest is distributed in the hope that it will be useful, but
18  WITHOUT ANY WARRANTY; without even the implied warranty of
19  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20  General Public License for more details.
21
22  You should have received a copy of the GNU General Public License
23  along with svndigest. If not, see <http://www.gnu.org/licenses/>.
24*/
25
26#include <iosfwd>
27#include <string>
28#include <vector>
29
30namespace theplu{
31namespace svndigest{
32
33  /**
34     \brief differentiate code, comments, and blank lines
35     
36     Class gets parsing rules from Configuration. Which rules depends
37     on the filename. Typical use is then to add lines using the add
38     function, and the class builds an internal vector<line_type>,
39     which can be accessed through function type(void).
40  */
41  class LineTypeParser
42  {
43  public:
44    ///
45    /// see 'doc/readme.txt' for info on what is code, comment, and other.
46    ///
47    // do not change these without checking in Stats class
48    enum line_type {
49      copyright = 0,
50      other = 1,
51      comment = 2,
52      code = 3,
53      comment_or_copy = 4,
54      total = 5 // total should always be the largest
55    };
56
57    ///
58    /// @brief Constructor
59    /// \param filename is used to decide which parsing rules to use
60    ///
61    explicit LineTypeParser(std::string filename);
62
63    const std::string& block(void) const { return block_; }
64    inline bool copyright_found(void) const { return copyright_found_; }
65
66    inline size_t end_line(void) const { return end_line_; } 
67
68    /**
69       \brief add a line to parser
70
71       \return line_type of parsed line
72
73       The line is parsed and added to internal vector. 
74     */
75    line_type parse(std::string line);
76
77    const std::string& prefix(void) const { return copyright_prefix_; }
78
79    inline size_t start_line(void) const { return start_line_; } 
80
81    ///
82    /// @return const ref to vector with the line types
83    ///
84    inline const std::vector<line_type>& type(void) const { return type_; }
85
86  private:
87    // no copy allowed
88    LineTypeParser(const LineTypeParser& other);
89    LineTypeParser& operator=(const LineTypeParser&);
90
91    line_type code_mode(const std::string& line);
92    line_type text_mode(const std::string& line);
93
94    size_t mode_;
95    bool post_copyright_;
96    bool copyright_found_;
97    std::string copyright_prefix_;
98    std::string block_;
99    size_t start_line_;
100    size_t end_line_;
101   
102    std::vector<line_type> type_;
103    const std::vector<std::pair<std::string, std::string> >* codon_;
104  };
105
106  ///
107  /// @return true if @a c is [a-z], [A-Z] or numerical.
108  ///
109  struct AlphaNum : public std::unary_function<char,bool>
110  {
111    inline bool operator()(const char c) const
112    { 
113      return isalnum(c); 
114    }
115  };
116
117  ///
118  /// Functor for white space identification
119  ///
120  /// @see isspace
121  ///
122  /// @return true if @a c is '\t', '\n', '\v', '\f' or ' '.
123  ///
124  struct WhiteSpace : public std::unary_function<char,bool>
125  {
126    inline bool operator()(const char c) const
127    { 
128      return isspace(c); 
129    }
130  };
131
132}} // end of namespace svndigest end of namespace theplu
133
134#endif
Note: See TracBrowser for help on using the repository browser.