Cupt
stringrange.hpp
1/**************************************************************************
2* Copyright (C) 2014 by Eugene V. Lyubimkin *
3* *
4* This program is free software; you can redistribute it and/or modify *
5* it under the terms of the GNU General Public License *
6* (version 3 or above) as published by the Free Software Foundation. *
7* *
8* This program is distributed in the hope that it will be useful, *
9* but WITHOUT ANY WARRANTY; without even the implied warranty of *
10* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
11* GNU General Public License for more details. *
12* *
13* You should have received a copy of the GNU GPL *
14* along with this program; if not, write to the *
15* Free Software Foundation, Inc., *
16* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA *
17**************************************************************************/
18#ifndef CUPT_STRINGRANGE_SEEN
19#define CUPT_STRINGRANGE_SEEN
20
21#include <cupt/range.hpp>
22
23#include <string>
24#include <algorithm>
25
26namespace cupt {
27
28struct StringRange: public Range<const char*>
29{
30 // for boost::range
31 typedef Iterator iterator;
32 typedef Iterator const_iterator;
33
35
37 {}
38
39 StringRange(const std::string& s)
40 : Base(&*s.begin(), &*s.end())
41 {}
42
43 StringRange(Iterator a, Iterator b)
44 : Base(a, b)
45 {}
46
47 std::string toStdString() const
48 {
49 return std::string(begin(), end());
50 }
51
52 Iterator find(char c) const
53 {
54 return std::find(begin(), end(), c);
55 }
56
57 size_t size() const
58 {
59 return end() - begin();
60 }
61
62 bool equal(StringRange other) const
63 {
64 return size() == other.size() &&
65 std::equal(begin(), end(), other.begin());
66 }
67};
68
69}
70
71#endif
72
Definition range.hpp:28
Definition stringrange.hpp:29