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)
5  2022, Hermann Vosseler <Ichthyostega@web.de>
6 
7   **Lumiera** is free software; you can redistribute it and/or modify it
8   under the terms of the GNU General Public License as published by the
9   Free Software Foundation; either version 2 of the License, or (at your
10   option) any later version. See the file COPYING for further details.
11 
12 */
13 
14 
20 #ifndef LIB_REGEX_H
21 #define LIB_REGEX_H
22 
23 
24 #include "lib/iter-adapter.hpp"
25 
26 #include <regex>
27 #include <string>
28 #include <optional>
29 
30 namespace util {
31 
32  using std::regex;
33  using std::smatch;
34  using std::string;
35  using std::string_view;
36 
37 
38 
41  : std::sregex_iterator
42  {
43  RegexSearchIter() = default;
44 
45  RegexSearchIter (string const& toParse, regex const& regex)
46  : std::sregex_iterator{toParse.begin(), toParse.end(), regex}
47  { }
48  RegexSearchIter (string_view toParse, regex const& regex)
49  : std::sregex_iterator{string::const_iterator{toParse.begin()}
50  ,string::const_iterator{toParse.end()}, regex}
51  { }
52 
53  operator bool() const { return isValid(); }
54 
55  bool isValid () const { return (*this)->ready() and not (*this)->empty(); }
56  bool empty () const { return not isValid(); }
57 
58  LIFT_PARENT_INCREMENT_OPERATOR (std::sregex_iterator);
59  ENABLE_USE_IN_STD_RANGE_FOR_LOOPS (RegexSearchIter);
60  };
61 
62 }// namespace util
63 
64 namespace lib {
65  using std::regex;
66  using std::smatch;
67  using std::string;
68 }// namespace lib
69 #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:40