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