diff options
-rw-r--r-- | include/Regex.h | 7 | ||||
-rw-r--r-- | lib/Regex.cc | 21 |
2 files changed, 22 insertions, 6 deletions
diff --git a/include/Regex.h b/include/Regex.h index 1fc7197..9c8d466 100644 --- a/include/Regex.h +++ b/include/Regex.h @@ -4,17 +4,18 @@ #include <Exceptions.h> #include <String.h> - #include <regex.h> class Regex : public Base { public: - Regex(const String &, int = REG_EXTENDED | REG_ICASE, int = 0) throw (GeneralException); + Regex(const String &, int = REG_EXTENDED, int = 0) throw (GeneralException); + Regex(const Regex &); ~Regex(); bool Match(const String &) const; private: regex_t preg; - int eflags; + int cflags, eflags; + char * pattern; }; extern Regex empty, any; diff --git a/lib/Regex.cc b/lib/Regex.cc index 9b70d68..3c566bd 100644 --- a/lib/Regex.cc +++ b/lib/Regex.cc @@ -2,18 +2,33 @@ char t[1024]; -Regex empty("$^"), any(".*"); +Regex empty("^$"), any(".*"); -Regex::Regex(const String & regex, int cflags, int aeflags) throw (GeneralException) : eflags(aeflags) { +Regex::Regex(const String & regex, int acflags, int aeflags) throw (GeneralException) : cflags(acflags), eflags(aeflags), pattern(regex.strdup()) { int r; - if ((r = regcomp(&preg, regex.to_charp(), cflags | REG_NOSUB))) { + + if ((r = regcomp(&preg, pattern, cflags | REG_NOSUB))) { + cerr << "Error in regcomp:"; regerror(r, &preg, t, sizeof(t)); + cerr << t << endl; throw GeneralException(String("Regex \"") + regex + "\" failed to compile: " + t + "\n"); } } +Regex::Regex(const Regex & regex) : pattern(Base::strdup(pattern)) { + int r; + + if ((r = regcomp(&preg, pattern, cflags | REG_NOSUB))) { + cerr << "Error in regcomp:"; + regerror(r, &preg, t, sizeof(t)); + cerr << t << endl; + throw GeneralException(String("Regex \"") + pattern + "\" failed to compile: " + t + "\n"); + } +} + Regex::~Regex() { regfree(&preg); + free(pattern); } bool Regex::Match(const String & s) const { |