1 | #ifndef _theplu_svndigest_parser_ |
---|
2 | #define _theplu_svndigest_parser_ |
---|
3 | |
---|
4 | // $Id: Parser.h 339 2007-05-19 09:33:08Z 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://lev.thep.lu.se/trac/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 | |
---|
32 | namespace theplu{ |
---|
33 | namespace svndigest{ |
---|
34 | |
---|
35 | /// |
---|
36 | /// Class parsing files |
---|
37 | /// |
---|
38 | class Parser |
---|
39 | { |
---|
40 | public: |
---|
41 | /// |
---|
42 | /// A line is considered empty if it only contains spaces and tabs. |
---|
43 | /// |
---|
44 | /// A line is considered a comment if first and second non-white |
---|
45 | /// space characters are '/'. |
---|
46 | /// |
---|
47 | /// All other lines are considered code. |
---|
48 | /// |
---|
49 | enum line_type { |
---|
50 | empty, |
---|
51 | comment, |
---|
52 | code |
---|
53 | }; |
---|
54 | |
---|
55 | /// |
---|
56 | /// @brief Constructor |
---|
57 | /// |
---|
58 | explicit Parser(std::string); |
---|
59 | |
---|
60 | /// |
---|
61 | /// @return const ref to vector with the line types |
---|
62 | /// |
---|
63 | inline const std::vector<line_type>& type(void) const { return type_; } |
---|
64 | |
---|
65 | private: |
---|
66 | /// |
---|
67 | /// Copy constructor (not implemented) |
---|
68 | /// |
---|
69 | Parser(const Parser& other); |
---|
70 | |
---|
71 | void parse(std::istream& is, |
---|
72 | std::vector<std::pair<std::string, std::string> >& codon); |
---|
73 | |
---|
74 | void text_mode(std::istream&); |
---|
75 | |
---|
76 | std::vector<line_type> type_; |
---|
77 | |
---|
78 | }; |
---|
79 | |
---|
80 | /// |
---|
81 | /// @return true if @a c is [a-z], [A-Z] or numerical. |
---|
82 | /// |
---|
83 | struct AlphaNum : public std::unary_function<char,bool> |
---|
84 | { |
---|
85 | inline bool operator()(const char c) const |
---|
86 | { |
---|
87 | return isalnum(c); |
---|
88 | } |
---|
89 | }; |
---|
90 | |
---|
91 | /// |
---|
92 | /// Functor for white space identification |
---|
93 | /// |
---|
94 | /// @see isspace |
---|
95 | /// |
---|
96 | /// @return true if @a c is '\t', '\n', '\v', '\f' or ' '. |
---|
97 | /// |
---|
98 | struct WhiteSpace : public std::unary_function<char,bool> |
---|
99 | { |
---|
100 | inline bool operator()(const char c) const |
---|
101 | { |
---|
102 | return isspace(c); |
---|
103 | } |
---|
104 | }; |
---|
105 | |
---|
106 | }} // end of namespace svndigest end of namespace theplu |
---|
107 | |
---|
108 | #endif |
---|