diff --git a/snapper/Makefile.am b/snapper/Makefile.am index 85982ae..6ce21aa 100644 --- a/snapper/Makefile.am +++ b/snapper/Makefile.am @@ -25,7 +25,6 @@ libsnapper_la_SOURCES = \ Compare.cc Compare.h \ SystemCmd.cc SystemCmd.h \ AsciiFile.cc AsciiFile.h \ - Regex.cc Regex.h \ Acls.cc Acls.h \ Hooks.cc Hooks.h \ Exception.cc Exception.h \ diff --git a/snapper/Regex.cc b/snapper/Regex.cc deleted file mode 100644 index 26962c1..0000000 --- a/snapper/Regex.cc +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright (c) [2004-2011] Novell, Inc. - * - * All Rights Reserved. - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of version 2 of the GNU General Public License as published - * by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, contact Novell, Inc. - * - * To contact Novell about this file by physical or electronic mail, you may - * find current contact information at www.novell.com. - */ - - -// This file is obsolete. It is only present for compatibility of libsnapper, esp. the -// Regex class was used in older versions of the zypp-plugin and we must avoid potentially -// problems during updates. - - -#include -#include "snapper/Regex.h" - -extern int _nl_msg_cat_cntr; - - -namespace snapper -{ - -Regex::Regex (const string& pattern, int cflags, unsigned int nm) - : pattern (pattern), - cflags (cflags), - nm (cflags & REG_NOSUB ? 0 : nm) -{ - int errcode = regcomp (&rx, pattern.c_str (), cflags); - if (errcode) { - size_t esize = regerror(errcode, &rx, nullptr, 0); - char error[esize]; - regerror(errcode, &rx, error, esize); - throw std::runtime_error(string("Regex compilation error: ") + error); - } - my_nl_msg_cat_cntr = _nl_msg_cat_cntr; - rm = new regmatch_t[nm]; -} - - -Regex::~Regex () -{ - delete [] rm; - regfree (&rx); -} - - -bool -Regex::match (const string& str, int eflags) const -{ - if (my_nl_msg_cat_cntr != _nl_msg_cat_cntr) { - regfree (&rx); - regcomp (&rx, pattern.c_str (), cflags); - my_nl_msg_cat_cntr = _nl_msg_cat_cntr; - } - - last_str = str; - - return regexec (&rx, str.c_str (), nm, rm, eflags) == 0; -} - - -regoff_t -Regex::so (unsigned int i) const -{ - return i < nm ? rm[i].rm_so : -1; -} - - -regoff_t -Regex::eo (unsigned int i) const -{ - return i < nm ? rm[i].rm_eo : -1; -} - - -string -Regex::cap (unsigned int i) const -{ - if (i < nm && rm[i].rm_so > -1) - return last_str.substr (rm[i].rm_so, rm[i].rm_eo - rm[i].rm_so); - return ""; -} - - -const string Regex::ws = "[ \t]*"; -const string Regex::number = "[0123456789]+"; -const string Regex::trailing_comment = "(#.*)?"; - -} diff --git a/snapper/Regex.h b/snapper/Regex.h deleted file mode 100644 index cd47686..0000000 --- a/snapper/Regex.h +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright (c) [2004-2012] Novell, Inc. - * - * All Rights Reserved. - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of version 2 of the GNU General Public License as published - * by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, contact Novell, Inc. - * - * To contact Novell about this file by physical or electronic mail, you may - * find current contact information at www.novell.com. - */ - - -// This file is obsolete. It is only present for compatibility of libsnapper, esp. the -// Regex class was used in older versions of the zypp-plugin and we must avoid potentially -// problems during updates. - - -#ifndef SNAPPER_REGEX_H -#define SNAPPER_REGEX_H - - -#include -#include -#include - - -namespace snapper -{ - using std::string; - - -class Regex : private boost::noncopyable -{ -public: - - Regex (const string& pattern, int cflags = REG_EXTENDED, unsigned int = 10); - ~Regex (); - - string getPattern () const { return pattern; } - int getCflags () const { return cflags; } - - bool match (const string&, int eflags = 0) const; - - regoff_t so (unsigned int) const; - regoff_t eo (unsigned int) const; - - string cap (unsigned int) const; - - static const string ws; - static const string number; - static const string trailing_comment; - -private: - - const string pattern; - const int cflags; - const unsigned int nm; - - mutable regex_t rx; - mutable int my_nl_msg_cat_cntr; - mutable regmatch_t* rm; - - mutable string last_str; -}; - -} - -#endif