libshevek
regexp.hh
1 /* regexp.hh - regular expressions
2  * Copyright 2004 Bas Wijnen <wijnen@debian.org>
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 as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef SHEVEK_REGEXP_HH
19 #define SHEVEK_REGEXP_HH
20 
21 #include <glibmm.h>
22 #include <sys/types.h>
23 #include <regex.h>
24 #include "debug.hh"
25 
26 namespace shevek
27 {
29  class regexp
30  {
31  regex_t m_buffer;
32  bool m_case_sensitive;
33  regmatch_t *m_match;
34  unsigned m_size;
35  std::string m_pattern, m_data;
36  void l_setup (std::string const &pattern, bool destroy);
37  public:
39  regexp (std::string const &pattern = std::string (),
40  bool case_sensitive = false);
42  regexp &operator= (std::string const &pattern);
44  regexp (regexp const &that);
46  regexp &operator= (regexp const &that);
48  void case_sensitive (bool value = true);
50  ~regexp ();
52  bool operator() (std::string const &data);
54 
56  std::string operator[] (unsigned idx) const;
58  bool valid (unsigned idx) const;
60  unsigned size () const;
62  std::string transform (std::string const &data) const;
64  std::string const &pattern () const;
65  };
66 }
67 
68 #endif