source: trunk/lib/Parser.h @ 125

Last change on this file since 125 was 125, checked in by Jari Häkkinen, 17 years ago

Cleaning.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.2 KB
Line 
1// $Id: Parser.h 125 2006-08-01 22:47:30Z jari $
2
3/*
4  Copyright (C) 2006 Peter Johansson
5
6  This file is part of svnstat, http://lev.thep.lu.se/trac/svnstat
7
8  svnstat is free software; you can redistribute it and/or modify it
9  under the terms of the GNU General Public License as published by
10  the Free Software Foundation; either version 2 of the License, or
11  (at your option) any later version.
12
13  svnstat is distributed in the hope that it will be useful, but
14  WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  General Public License for more details.
17
18  You should have received a copy of the GNU General Public License
19  along with this program; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
21  02111-1307, USA.
22*/
23
24#ifndef _theplu_svnstat_parser_
25#define _theplu_svnstat_parser_
26
27#include <fstream>
28#include <string>
29#include <vector>
30
31namespace theplu{
32namespace svnstat{
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    std::vector<line_type> type_;
73
74  };
75
76  ///
77  /// @return true if @a c is [a-z], [A-Z] or numerical.
78  ///
79  struct AlphaNum : public std::unary_function<char,bool>
80  {
81    inline bool operator()(const char c) const
82    { 
83      return isalnum(c); 
84    }
85  };
86
87  ///
88  /// Functor for white space identification
89  ///
90  /// @see isspace
91  ///
92  /// @return true if @a c is '\t', '\n', '\v', '\f' or ' '.
93  ///
94  struct WhiteSpace : public std::unary_function<char,bool>
95  {
96    inline bool operator()(const char c) const
97    { 
98      return isspace(c); 
99    }
100  };
101
102}} // end of namespace svnstat end of namespace theplu
103
104#endif
Note: See TracBrowser for help on using the repository browser.