source: trunk/lib/LineTypeParser.h @ 687

Last change on this file since 687 was 687, checked in by Peter Johansson, 13 years ago

Merged patch release 0.6.6 to trunk. Delta 0.6.6 - 0.6.5

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.5 KB
Line 
1#ifndef _theplu_svndigest_line_type_parser_
2#define _theplu_svndigest_line_type_parser_
3
4// $Id: LineTypeParser.h 687 2008-08-04 19:37:10Z peter $
5
6/*
7  Copyright (C) 2006 Jari Häkkinen, Peter Johansson
8  Copyright (C) 2007 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 2 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 this program; if not, write to the Free Software
24  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
25  02111-1307, USA.
26*/
27
28#include <iosfwd>
29#include <string>
30#include <vector>
31
32namespace theplu{
33namespace svndigest{
34
35  /**
36     \brief differentiate code, comments, and blank lines
37     
38     Class gets parsing rules from Configuration. Which rules depends
39     on the filename. Typical use is then to add lines using the add
40     function, and the class builds an internal vector<line_type>,
41     which can be accessed through function type(void).
42  */
43  class LineTypeParser
44  {
45  public:
46    ///
47    /// see 'doc/readmea.txt' for info on what is code, comment, and other.
48    ///
49    // do not change these without checking in Stats class
50    enum line_type {
51      copyright = 0,
52      other = 1,
53      comment = 2,
54      code = 3,
55      comment_or_copy = 4,
56      total = 5 // total should always be the largest
57    };
58
59    ///
60    /// @brief Constructor
61    /// \param filename is used to decide which parsing rules to use
62    ///
63    explicit LineTypeParser(std::string filename);
64
65    const std::string& block(void) const { return block_; }
66    inline bool copyright_found(void) const { return copyright_found_; }
67
68    inline size_t end_line(void) const { return end_line_; } 
69
70    /**
71       \brief add a line to parser
72
73       \return line_type of parsed line
74
75       The line is parsed and added to internal vector. 
76     */
77    line_type parse(std::string line);
78
79    const std::string& prefix(void) const { return copyright_prefix_; }
80
81    inline size_t start_line(void) const { return start_line_; } 
82
83    ///
84    /// @return const ref to vector with the line types
85    ///
86    inline const std::vector<line_type>& type(void) const { return type_; }
87
88  private:
89    // no copy allowed
90    LineTypeParser(const LineTypeParser& other);
91    LineTypeParser& operator=(const LineTypeParser&);
92
93    line_type code_mode(const std::string& line);
94    line_type text_mode(const std::string& line);
95
96    size_t mode_;
97    bool post_copyright_;
98    bool copyright_found_;
99    std::string copyright_prefix_;
100    std::string block_;
101    size_t start_line_;
102    size_t end_line_;
103   
104    std::vector<line_type> type_;
105    const std::vector<std::pair<std::string, std::string> >* codon_;
106  };
107
108  ///
109  /// @return true if @a c is [a-z], [A-Z] or numerical.
110  ///
111  struct AlphaNum : public std::unary_function<char,bool>
112  {
113    inline bool operator()(const char c) const
114    { 
115      return isalnum(c); 
116    }
117  };
118
119  ///
120  /// Functor for white space identification
121  ///
122  /// @see isspace
123  ///
124  /// @return true if @a c is '\t', '\n', '\v', '\f' or ' '.
125  ///
126  struct WhiteSpace : public std::unary_function<char,bool>
127  {
128    inline bool operator()(const char c) const
129    { 
130      return isspace(c); 
131    }
132  };
133
134}} // end of namespace svndigest end of namespace theplu
135
136#endif
Note: See TracBrowser for help on using the repository browser.