1549 |
24 Oct 12 |
peter |
1 |
#ifndef theplu_svndigest_skip_white_space_iterator |
1549 |
24 Oct 12 |
peter |
2 |
#define theplu_svndigest_skip_white_space_iterator |
1549 |
24 Oct 12 |
peter |
3 |
|
1549 |
24 Oct 12 |
peter |
// $Id$ |
1549 |
24 Oct 12 |
peter |
5 |
|
1549 |
24 Oct 12 |
peter |
6 |
/* |
1549 |
24 Oct 12 |
peter |
Copyright (C) 2012 Peter Johansson |
1549 |
24 Oct 12 |
peter |
8 |
|
1549 |
24 Oct 12 |
peter |
This file is part of svndigest, http://dev.thep.lu.se/svndigest |
1549 |
24 Oct 12 |
peter |
10 |
|
1549 |
24 Oct 12 |
peter |
svndigest is free software; you can redistribute it and/or modify it |
1549 |
24 Oct 12 |
peter |
under the terms of the GNU General Public License as published by |
1549 |
24 Oct 12 |
peter |
the Free Software Foundation; either version 3 of the License, or |
1549 |
24 Oct 12 |
peter |
(at your option) any later version. |
1549 |
24 Oct 12 |
peter |
15 |
|
1549 |
24 Oct 12 |
peter |
svndigest is distributed in the hope that it will be useful, but |
1549 |
24 Oct 12 |
peter |
WITHOUT ANY WARRANTY; without even the implied warranty of |
1549 |
24 Oct 12 |
peter |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
1549 |
24 Oct 12 |
peter |
General Public License for more details. |
1549 |
24 Oct 12 |
peter |
20 |
|
1549 |
24 Oct 12 |
peter |
You should have received a copy of the GNU General Public License |
1549 |
24 Oct 12 |
peter |
along with svndigest. If not, see <http://www.gnu.org/licenses/>. |
1549 |
24 Oct 12 |
peter |
23 |
*/ |
1549 |
24 Oct 12 |
peter |
24 |
|
1549 |
24 Oct 12 |
peter |
25 |
#include <iterator> |
1549 |
24 Oct 12 |
peter |
26 |
#include <string> |
1549 |
24 Oct 12 |
peter |
27 |
|
1549 |
24 Oct 12 |
peter |
28 |
namespace theplu { |
1549 |
24 Oct 12 |
peter |
29 |
namespace svndigest { |
1549 |
24 Oct 12 |
peter |
30 |
|
1549 |
24 Oct 12 |
peter |
31 |
/** |
1549 |
24 Oct 12 |
peter |
\brief A wrapper around std::string::const_iterator. |
1549 |
24 Oct 12 |
peter |
33 |
|
1549 |
24 Oct 12 |
peter |
Iterator behaves as its base std::string::const_iterator except |
1549 |
24 Oct 12 |
peter |
when incremented it skips white-spaces. Iterator is non-mutable |
1549 |
24 Oct 12 |
peter |
and only have forward iterator features, i.e., no random |
1549 |
24 Oct 12 |
peter |
access. Iterator could easily be extended to be a bidirectional |
1549 |
24 Oct 12 |
peter |
iterator by adding a 'operator--'. |
1549 |
24 Oct 12 |
peter |
39 |
|
1549 |
24 Oct 12 |
peter |
Constructor takes an end-of-range iterator that typically is |
1549 |
24 Oct 12 |
peter |
'std::string::end()'. This is needed because when 'base_' |
1549 |
24 Oct 12 |
peter |
iterates out of range, 'base_' is not dereferencable and it is |
1549 |
24 Oct 12 |
peter |
thus impossible to check if iterator points to a |
1549 |
24 Oct 12 |
peter |
white-space. Instead we stop incrementing 'base_' as soon as it |
1549 |
24 Oct 12 |
peter |
reaches 'end_'. |
1549 |
24 Oct 12 |
peter |
46 |
*/ |
1549 |
24 Oct 12 |
peter |
47 |
class SkipWhiteSpaceIterator |
1549 |
24 Oct 12 |
peter |
48 |
{ |
1549 |
24 Oct 12 |
peter |
49 |
public: |
1549 |
24 Oct 12 |
peter |
50 |
typedef std::forward_iterator_tag iterator_category; |
1549 |
24 Oct 12 |
peter |
51 |
typedef std::string::const_iterator::value_type value_type; |
1549 |
24 Oct 12 |
peter |
52 |
typedef std::string::const_iterator::difference_type difference_type; |
1549 |
24 Oct 12 |
peter |
53 |
typedef std::string::const_iterator::pointer pointer; |
1549 |
24 Oct 12 |
peter |
54 |
typedef std::string::const_iterator::reference reference; |
1549 |
24 Oct 12 |
peter |
55 |
|
1549 |
24 Oct 12 |
peter |
56 |
/** |
1549 |
24 Oct 12 |
peter |
Create iterator pointing to same item as \a iter. |
1549 |
24 Oct 12 |
peter |
58 |
|
1549 |
24 Oct 12 |
peter |
\a end defines end of range and the iterator will not iterate |
1549 |
24 Oct 12 |
peter |
passed this point. |
1549 |
24 Oct 12 |
peter |
61 |
*/ |
1549 |
24 Oct 12 |
peter |
62 |
SkipWhiteSpaceIterator(std::string::const_iterator iter, |
1549 |
24 Oct 12 |
peter |
63 |
std::string::const_iterator end); |
1549 |
24 Oct 12 |
peter |
64 |
|
1549 |
24 Oct 12 |
peter |
65 |
/** |
1549 |
24 Oct 12 |
peter |
return underlying string iterator |
1549 |
24 Oct 12 |
peter |
67 |
*/ |
1549 |
24 Oct 12 |
peter |
68 |
const std::string::const_iterator& base(void) const; |
1549 |
24 Oct 12 |
peter |
69 |
|
1549 |
24 Oct 12 |
peter |
70 |
/** |
1549 |
24 Oct 12 |
peter |
return const reference to character |
1549 |
24 Oct 12 |
peter |
72 |
*/ |
1549 |
24 Oct 12 |
peter |
73 |
reference operator*(void) const; |
1549 |
24 Oct 12 |
peter |
74 |
|
1549 |
24 Oct 12 |
peter |
75 |
/** |
1549 |
24 Oct 12 |
peter |
return pointer |
1549 |
24 Oct 12 |
peter |
77 |
*/ |
1549 |
24 Oct 12 |
peter |
78 |
pointer operator->(void) const; |
1549 |
24 Oct 12 |
peter |
79 |
|
1549 |
24 Oct 12 |
peter |
80 |
/** |
1549 |
24 Oct 12 |
peter |
Increment iterator to next non-white-space character or end |
1549 |
24 Oct 12 |
peter |
position. |
1549 |
24 Oct 12 |
peter |
83 |
*/ |
1549 |
24 Oct 12 |
peter |
84 |
SkipWhiteSpaceIterator& operator++(void); |
1549 |
24 Oct 12 |
peter |
85 |
|
1549 |
24 Oct 12 |
peter |
86 |
private: |
1549 |
24 Oct 12 |
peter |
87 |
std::string::const_iterator base_; |
1549 |
24 Oct 12 |
peter |
88 |
std::string::const_iterator end_; |
1549 |
24 Oct 12 |
peter |
// user compiler generated copy |
1549 |
24 Oct 12 |
peter |
//SkipWhiteSpaceIterator(const SkipWhiteSpaceIterator&); |
1549 |
24 Oct 12 |
peter |
//SkipWhiteSpaceIterator& operator=(const SkipWhiteSpaceIterator&); |
1549 |
24 Oct 12 |
peter |
92 |
}; |
1549 |
24 Oct 12 |
peter |
93 |
|
1549 |
24 Oct 12 |
peter |
94 |
bool operator==(const SkipWhiteSpaceIterator& lhs, |
1549 |
24 Oct 12 |
peter |
95 |
const SkipWhiteSpaceIterator& rhs); |
1549 |
24 Oct 12 |
peter |
96 |
|
1549 |
24 Oct 12 |
peter |
97 |
bool operator!=(const SkipWhiteSpaceIterator& lhs, |
1549 |
24 Oct 12 |
peter |
98 |
const SkipWhiteSpaceIterator& rhs); |
1549 |
24 Oct 12 |
peter |
99 |
|
1549 |
24 Oct 12 |
peter |
100 |
|
1549 |
24 Oct 12 |
peter |
101 |
}} // end of namespace svndigest and namespace theplu |
1549 |
24 Oct 12 |
peter |
102 |
#endif |