#include "debug.h" #include "regexwrap.h" namespace { void utils_regex_init( utils_regex& self, const std::string& pattern, int cflags) { self.pattern = pattern; self.cflags = cflags; self.query_is_bad = false; if ( self.pattern=="") self.pattern="."; if ( int e = regcomp( &self.reg, self.pattern.c_str(), self.cflags)) { (void) e; self.query_is_bad = true; } debug0 << "compiled regex " << self.pattern << "\n"; } } utils_regex::utils_regex( const std::string& pattern, int cflags) { utils_regex_init( *this, pattern, cflags); } utils_regex::utils_regex( const utils_regex& rhs) { utils_regex_init( *this, rhs.pattern, rhs.cflags); } utils_regex& utils_regex::operator=( const utils_regex& rhs) { if ( !this->query_is_bad) regfree( &this->reg); utils_regex_init( *this, rhs.pattern, rhs.cflags); return *this; } utils_regex::~utils_regex() { if ( !this->query_is_bad) regfree( &this->reg); }