00001 #ifndef REGEX_H 00002 #define REGEX_H 00003 00004 #include <pcre/pcre.h> 00005 #include <abuse/RefCounted.h> 00006 #include <string> 00007 #include <stdexcept> 00008 #include <utility> 00009 00010 class RegEx 00011 { 00012 public: 00013 RegEx(const std::string& pattern, int size=90)throw(std::runtime_error); 00014 virtual ~RegEx(); 00015 void operator=(const std::string& pattern)throw(std::runtime_error); 00016 //pair<int,size_t> returns the pos of the match, and the size of the same 00017 //pair<int,size_t> (-1,0) means no matches. 00018 std::pair<int,size_t> match(const std::string& what,int from=0)const throw(std::runtime_error); 00019 std::string operator[](const std::string& subpatt)const throw(std::runtime_error); 00020 std::string operator[](int n)const throw(std::runtime_error); 00021 private: 00022 struct PcreProxy 00023 { 00024 pcre* m_ptr; 00025 PcreProxy(pcre* ptr=NULL):m_ptr(ptr){} 00026 ~PcreProxy(){pcre_free(m_ptr);} 00027 }; 00028 RefCounted<PcreProxy> m_pcre; 00029 mutable int* m_pVector; 00030 int m_size; 00031 mutable std::string m_string; 00032 }; 00033 00034 #endif