Regex.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00012 #ifndef ZYPP_BASE_REGEX_H
00013 #define ZYPP_BASE_REGEX_H
00014
00015 #include <string>
00016 #include <regex.h>
00017
00018 #include "zypp/base/Exception.h"
00019
00021 namespace zypp
00022 {
00023
00024
00027 namespace str
00028 {
00029
00031
00042 typedef Exception regex_error;
00043
00044 class smatch;
00045 class regex;
00046
00047 bool regex_match(const char * s, str::smatch& matches, const regex& regex);
00048 inline bool regex_match(const std::string& s, str::smatch& matches, const regex& regex)
00049 { return regex_match( s.c_str(), matches, regex ); }
00050
00051 bool regex_match(const char * s, const regex& regex);
00052 inline bool regex_match(const std::string& s, const regex& regex)
00053 { return regex_match( s.c_str(), regex ); }
00054
00059 class regex {
00060 public:
00061
00062 enum RegFlags {
00063 optimize = 0,
00064 match_extra = 0,
00065 icase = REG_ICASE,
00066 nosubs = REG_NOSUB,
00067 match_extended = REG_EXTENDED,
00068 normal = 1<<16
00069 };
00070
00071 regex();
00072 regex(const std::string& s,int flags = match_extended);
00073 ~regex() throw();
00074
00075 regex(const regex & rhs)
00076 { assign(rhs.m_str, rhs.m_flags); }
00077
00078 regex & operator=(const regex & rhs)
00079 { assign(rhs.m_str, rhs.m_flags); return *this; }
00080
00084 std::string asString() const
00085 { return m_str; }
00086
00087 public:
00089 regex_t * get()
00090 { return & m_preg; }
00091
00092 private:
00093 void assign(const std::string& s,int flags = match_extended);
00094
00095 private:
00096 friend class smatch;
00097 friend bool regex_match(const char * s, str::smatch& matches, const regex& regex);
00098 friend bool regex_match(const char * s, const regex& regex);
00099 std::string m_str;
00100 int m_flags;
00101 regex_t m_preg;
00102 bool m_valid;
00103 };
00104
00109 class smatch {
00110 public:
00111 smatch();
00112
00113 std::string operator[](unsigned i) const;
00114
00115 unsigned size() const;
00116
00117 std::string match_str;
00118 regmatch_t pmatch[12];
00119 };
00120
00121
00122
00124 }
00127 }
00129 #endif // ZYPP_BASE_STRING_H