00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
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