00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef __OASYS_REGEX_H__
00019 #define __OASYS_REGEX_H__
00020
00021 #include <string>
00022 #include <sys/types.h>
00023 #include <regex.h>
00024
00025 namespace oasys {
00026
00027 class Regex {
00028 public:
00029 static const size_t MATCH_LIMIT = 8;
00030
00031 static int match(const char* regex, const char* str,
00032 int cflags = 0, int rflags = 0);
00033
00034 Regex(const char* regex, int cflags = 0);
00035 virtual ~Regex();
00036
00037 int match(const char* str, int flags = 0);
00038
00039 bool valid() { return compilation_err_ == 0; }
00040
00041 int num_matches();
00042 const regmatch_t& get_match(size_t i);
00043
00044 std::string regerror_str(int err);
00045
00046 protected:
00047 int compilation_err_;
00048
00049 regex_t regex_;
00050 regmatch_t matches_[MATCH_LIMIT];
00051 };
00052
00053 class Regsub : public Regex {
00054 public:
00055 static int subst(const char* regex, const char* str,
00056 const char* sub_spec, std::string* result,
00057 int cflags = 0, int rflags = 0);
00058
00059 Regsub(const char* regex, const char* sub_spec, int flags = 0);
00060 ~Regsub();
00061
00062 int subst(const char* str, std::string* result, int flags = 0);
00063
00064 protected:
00065 std::string sub_spec_;
00066 };
00067
00068 }
00069
00070 #endif