libshevek
src/regexp.hh
00001 /* regexp.hh - regular expressions
00002  * Copyright 2004 Bas Wijnen <wijnen@debian.org>
00003  *
00004  * This program is free software: you can redistribute it and/or modify
00005  * it under the terms of the GNU General Public License as published by
00006  * the Free Software Foundation, either version 3 of the License, or
00007  * (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00016  */
00017 
00018 #ifndef SHEVEK_REGEXP_HH
00019 #define SHEVEK_REGEXP_HH
00020 
00021 #include <glibmm.h>
00022 #include <sys/types.h>
00023 #include <regex.h>
00024 #include "debug.hh"
00025 
00026 namespace shevek
00027 {
00029   class regexp
00030   {
00031     regex_t m_buffer;
00032     bool m_case_sensitive;
00033     regmatch_t *m_match;
00034     unsigned m_size;
00035     std::string m_pattern, m_data;
00036     void l_setup (std::string const &pattern, bool destroy);
00037   public:
00039     regexp (std::string const &pattern = std::string (),
00040             bool case_sensitive = false);
00042     regexp &operator= (std::string const &pattern);
00044     regexp (regexp const &that);
00046     regexp &operator= (regexp const &that);
00048     void case_sensitive (bool value = true);
00050     ~regexp ();
00052     bool operator() (std::string const &data);
00054 
00056     std::string operator[] (unsigned idx) const;
00058     bool valid (unsigned idx) const;
00060     unsigned size () const;
00062     std::string transform (std::string const &data) const;
00064     std::string const &pattern () const;
00065   };
00066 }
00067 
00068 #endif