source: trunk/lib/Parser.h @ 218

Last change on this file since 218 was 218, checked in by Peter Johansson, 15 years ago

refs #69 added text-mode for parsing. For time being "*.txt", "AUTHORS", "ChangeLog?", "INSTALL", "NEWS", and "README" are parsed in this mode.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.3 KB
Line 
1#ifndef _theplu_svndigest_parser_
2#define _theplu_svndigest_parser_
3
4// $Id: Parser.h 218 2006-10-01 08:17:47Z peter $
5
6/*
7  Copyright (C) 2006 Jari Häkkinen, Peter Johansson
8
9  This file is part of svndigest, http://lev.thep.lu.se/trac/svndigest
10
11  svndigest is free software; you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation; either version 2 of the License, or
14  (at your option) any later version.
15
16  svndigest is distributed in the hope that it will be useful, but
17  WITHOUT ANY WARRANTY; without even the implied warranty of
18  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  General Public License for more details.
20
21  You should have received a copy of the GNU General Public License
22  along with this program; if not, write to the Free Software
23  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
24  02111-1307, USA.
25*/
26
27#include <iosfwd>
28#include <string>
29#include <vector>
30
31namespace theplu{
32namespace svndigest{
33
34  ///
35  /// Class parsing files
36  ///
37  class Parser
38  {
39  public:
40    ///
41    /// A line is considered empty if it only contains spaces and tabs.
42    ///
43    /// A line is considered a comment if first and second non-white
44    /// space characters are '/'.
45    ///
46    /// All other lines are considered code.
47    ///
48    enum line_type {
49      empty,
50      comment,
51      code
52    };
53
54    ///
55    /// @brief Constructor
56    ///
57    explicit Parser(const std::string&);
58
59    ///
60    /// @return const ref to vector with the line types
61    ///
62    inline const std::vector<line_type>& type(void) const { return type_; }
63
64  private:
65    ///
66    /// Copy constructor (not implemented)
67    ///
68    Parser(const Parser& other);
69
70    void cc_mode(std::istream&);
71
72    void line_com_mode(std::istream& is, const std::string& com_start);
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
Note: See TracBrowser for help on using the repository browser.