diff options
Diffstat (limited to 'lib/Regex.cc')
-rw-r--r-- | lib/Regex.cc | 21 |
1 files changed, 18 insertions, 3 deletions
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 { |