source: trunk/lib/Parser.h @ 540

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

fixes automatic update of revision and copyright year in --version output. Options --version and --verbose can no be combined to get a slightly more detailed description.

  • 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 540 2007-12-29 02:40:23Z 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      copyright,
51      other,
52      comment,
53      code
54    };
55
56    ///
57    /// @brief Constructor
58    /// \param filename is used to decide which parsing rules to use
59    ///
60    explicit Parser(std::string filename);
61
62    /**
63       \brief add a line to parser
64
65       \return line_type of parsed line
66
67       The line is parsed and added to internal vector. 
68     */
69    line_type parse(const std::string& line);
70
71    ///
72    /// @return const ref to vector with the line types
73    ///
74    inline const std::vector<line_type>& type(void) const { return type_; }
75
76  private:
77    // no copy allowed
78    Parser(const Parser& other);
79    Parser& operator=(const Parser&);
80
81    line_type code_mode(const std::string& line);
82    line_type text_mode(const std::string& line);
83
84    size_t mode_;
85   
86    std::vector<line_type> type_;
87    const std::vector<std::pair<std::string, std::string> >* codon_;
88  };
89
90  ///
91  /// @return true if @a c is [a-z], [A-Z] or numerical.
92  ///
93  struct AlphaNum : public std::unary_function<char,bool>
94  {
95    inline bool operator()(const char c) const
96    { 
97      return isalnum(c); 
98    }
99  };
100
101  ///
102  /// Functor for white space identification
103  ///
104  /// @see isspace
105  ///
106  /// @return true if @a c is '\t', '\n', '\v', '\f' or ' '.
107  ///
108  struct WhiteSpace : public std::unary_function<char,bool>
109  {
110    inline bool operator()(const char c) const
111    { 
112      return isspace(c); 
113    }
114  };
115
116}} // end of namespace svndigest end of namespace theplu
117
118#endif
Note: See TracBrowser for help on using the repository browser.