diff --git a/src/RX.cpp b/src/RX.cpp index 876cc2bfc..4f0ebe967 100644 --- a/src/RX.cpp +++ b/src/RX.cpp @@ -29,6 +29,14 @@ #include #include +//////////////////////////////////////////////////////////////////////////////// +RX::RX () +: _compiled (false) +, _pattern ("") +, _case_sensitive (false) +{ +} + //////////////////////////////////////////////////////////////////////////////// RX::RX ( const std::string& pattern, @@ -40,6 +48,14 @@ RX::RX ( compile (); } +//////////////////////////////////////////////////////////////////////////////// +RX::RX (const RX& other) +{ + _compiled = false; + _pattern = other._pattern; + _case_sensitive = other._case_sensitive; +} + //////////////////////////////////////////////////////////////////////////////// RX::~RX () { @@ -47,10 +63,23 @@ RX::~RX () regfree (&_regex); } +//////////////////////////////////////////////////////////////////////////////// +RX& RX::operator= (const RX& other) +{ + if (this != &other) + { + _compiled = false; + _pattern = other._pattern; + _case_sensitive = other._case_sensitive; + } + + return *this; +} + //////////////////////////////////////////////////////////////////////////////// void RX::compile () { - if (!_compiled) + if (! _compiled) { memset (&_regex, 0, sizeof (regex_t)); @@ -75,7 +104,7 @@ void RX::compile () //////////////////////////////////////////////////////////////////////////////// bool RX::match (const std::string& in) { - if (!_compiled) + if (! _compiled) compile (); return regexec (&_regex, in.c_str (), 0, NULL, 0) == 0 ? true : false; @@ -86,7 +115,7 @@ bool RX::match ( std::vector& matches, const std::string& in) { - if (!_compiled) + if (! _compiled) compile (); regmatch_t rm[2]; @@ -112,7 +141,7 @@ bool RX::match ( std::vector & end, const std::string& in) { - if (!_compiled) + if (! _compiled) compile (); regmatch_t rm[2]; diff --git a/src/RX.h b/src/RX.h index bb2cfa72d..5a41ad22c 100644 --- a/src/RX.h +++ b/src/RX.h @@ -34,8 +34,11 @@ class RX { public: + RX (); RX (const std::string&, bool caseSensitive = true); + RX (const RX&); ~RX (); + RX& operator= (const RX&); bool match (const std::string&); bool match (std::vector&, const std::string&);