yast2-storage

Regex.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) [2004-2009] Novell, Inc.
00003  *
00004  * All Rights Reserved.
00005  *
00006  * This program is free software; you can redistribute it and/or modify it
00007  * under the terms of version 2 of the GNU General Public License as published
00008  * by the Free Software Foundation.
00009  *
00010  * This program is distributed in the hope that it will be useful, but WITHOUT
00011  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
00013  * more details.
00014  *
00015  * You should have received a copy of the GNU General Public License along
00016  * with this program; if not, contact Novell, Inc.
00017  *
00018  * To contact Novell about this file by physical or electronic mail, you may
00019  * find current contact information at www.novell.com.
00020  */
00021 
00022 
00023 #ifndef REGEX_H
00024 #define REGEX_H
00025 
00026 
00027 #include <regex.h>
00028 #include <string>
00029 #include <stdexcept>
00030 #include <boost/noncopyable.hpp>
00031 
00032 
00033 namespace storage
00034 {
00035     using std::string;
00036 
00037 
00038     class regex_error : public std::runtime_error
00039     {
00040     public:
00041         regex_error() : std::runtime_error("regex error") {}
00042     };
00043 
00044 
00045 class Regex : boost::noncopyable
00046 {
00047 public:
00048 
00049     Regex (const char* pattern, int cflags = REG_EXTENDED, unsigned int = 10);
00050     Regex (const string& pattern, int cflags = REG_EXTENDED, unsigned int = 10);
00051     ~Regex ();
00052 
00053     string getPattern () const { return pattern; }
00054     int getCflags () const { return cflags; }
00055 
00056     bool match (const string&, int eflags = 0) const;
00057 
00058     regoff_t so (unsigned int) const;
00059     regoff_t eo (unsigned int) const;
00060 
00061     string cap (unsigned int) const;
00062 
00063     static const string ws;
00064     static const string number;
00065 
00066     static string escape(const string& str);
00067 
00068 private:
00069 
00070     const string pattern;
00071     const int cflags;
00072     const unsigned int nm;
00073 
00074     mutable regex_t rx;
00075     mutable int my_nl_msg_cat_cntr;
00076     mutable regmatch_t* rm;
00077 
00078     mutable string last_str;
00079 };
00080 
00081 }
00082 
00083 #endif