00001 #ifndef DEBTAGS_REGEXP_H
00002 #define DEBTAGS_REGEXP_H
00003
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include <tagcoll/Exception.h>
00027 #include <sys/types.h>
00028 #include <regex.h>
00029
00030 namespace Debtags
00031 {
00032
00036 class RegexpException : public Tagcoll::SystemException
00037 {
00038 protected:
00039 std::string _message;
00040
00041 public:
00042 RegexpException(const regex_t& re, int code, const std::string& context)
00043 throw ();
00044 ~RegexpException() throw () {}
00045
00046 virtual const char* type() const throw () { return "RegexpException"; }
00047 virtual std::string desc() const throw () { return _message + " " + _context; }
00048 };
00049
00053 class Regexp
00054 {
00055 protected:
00056 regex_t re;
00057 regmatch_t* pmatch;
00058 int nmatch;
00059 std::string lastMatch;
00060
00061 public:
00062 Regexp(const std::string& expr, int match_count = 0, int flags = 0) throw (RegexpException);
00063 ~Regexp() throw ();
00064
00065 bool match(const std::string& str, int flags = 0) throw (RegexpException);
00066
00067 std::string operator[](int idx) throw (Tagcoll::OutOfRangeException);
00068 };
00069
00073 class ExtendedRegexp : public Regexp
00074 {
00075 public:
00076 ExtendedRegexp(const std::string& expr, int match_count = 0, int flags = 0) throw (RegexpException)
00077 : Regexp(expr, match_count, flags | REG_EXTENDED) {}
00078 };
00079
00080 };
00081
00082
00083 #endif