Lumiera  0.pre.03
»edit your freedom«
regex.hpp
Go to the documentation of this file.
1 /*
2  REGEX.hpp - helpers for working with regular expressions
3 
4  Copyright (C) Lumiera.org
5  2022, Hermann Vosseler <Ichthyostega@web.de>
6 
7  This program is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public License as
9  published by the Free Software Foundation; either version 2 of
10  the License, or (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 
21 */
22 
23 
29 #ifndef LIB_REGEX_H
30 #define LIB_REGEX_H
31 
32 
33 #include "lib/iter-adapter.hpp"
34 
35 #include <regex>
36 #include <string>
37 #include <optional>
38 
39 namespace util {
40 
41  using std::regex;
42  using std::smatch;
43  using std::string;
44  using std::string_view;
45 
46 
47 
50  : std::sregex_iterator
51  {
52  RegexSearchIter() = default;
53 
54  RegexSearchIter (string const& toParse, regex const& regex)
55  : std::sregex_iterator{toParse.begin(), toParse.end(), regex}
56  { }
57  RegexSearchIter (string_view toParse, regex const& regex)
58  : std::sregex_iterator{string::const_iterator{toParse.begin()}
59  ,string::const_iterator{toParse.end()}, regex}
60  { }
61 
62  operator bool() const { return isValid(); }
63 
64  bool isValid () const { return (*this)->ready() and not (*this)->empty(); }
65  bool empty () const { return not isValid(); }
66 
67  LIFT_PARENT_INCREMENT_OPERATOR (std::sregex_iterator);
68  ENABLE_USE_IN_STD_RANGE_FOR_LOOPS (RegexSearchIter);
69  };
70 
71 }// namespace util
72 
73 namespace lib {
74  using std::regex;
75  using std::smatch;
76  using std::string;
77 }// namespace lib
78 #endif/*LIB_STAT_REGEX_H*/
Helper template(s) for creating Lumiera Forward Iterators.
Implementation namespace for support and library code.
wrapped regex iterator to allow usage in foreach loops
Definition: regex.hpp:49