source: trunk/lib/Parser.h @ 536

Last change on this file since 536 was 536, checked in by Peter Johansson, 14 years ago

refs #289 - Parser now is fed with lines and does not read file during construction.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.8 KB
Line 
1#ifndef _theplu_svndigest_parser_
2#define _theplu_svndigest_parser_
3
4// $Id: Parser.h 536 2007-12-27 03:32:43Z 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://trac.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 Class parsing files
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 Parser
44  {
45  public:
46    ///
47    /// see 'doc/readmea.txt' for info on what is code, comment, and other.
48    ///
49    enum line_type {
50      other,
51      comment,
52      code
53    };
54
55    ///
56    /// @brief Constructor
57    /// \param filename is used to decide which parsing rules to use
58    ///
59    explicit Parser(std::string filename);
60
61    /**
62       \brief add a line to parser
63
64       \return line_type of parsed line
65
66       The line is parsed and added to internal vector. 
67     */
68    line_type parse(const std::string& line);
69
70    ///
71    /// @return const ref to vector with the line types
72    ///
73    inline const std::vector<line_type>& type(void) const { return type_; }
74
75  private:
76    // no copy allowed
77    Parser(const Parser& other);
78    Parser& operator=(const Parser&);
79
80    line_type code_mode(const std::string& line);
81    line_type text_mode(const std::string& line);
82
83    size_t mode_;
84   
85    std::vector<line_type> type_;
86    const std::vector<std::pair<std::string, std::string> >* codon_;
87  };
88
89  ///
90  /// @return true if @a c is [a-z], [A-Z] or numerical.
91  ///
92  struct AlphaNum : public std::unary_function<char,bool>
93  {
94    inline bool operator()(const char c) const
95    { 
96      return isalnum(c); 
97    }
98  };
99
100  ///
101  /// Functor for white space identification
102  ///
103  /// @see isspace
104  ///
105  /// @return true if @a c is '\t', '\n', '\v', '\f' or ' '.
106  ///
107  struct WhiteSpace : public std::unary_function<char,bool>
108  {
109    inline bool operator()(const char c) const
110    { 
111      return isspace(c); 
112    }
113  };
114
115}} // end of namespace svndigest end of namespace theplu
116
117#endif
Note: See TracBrowser for help on using the repository browser.