Skip to content
Snippets Groups Projects
Commit 12ac6a07 authored by Eric Cano's avatar Eric Cano
Browse files

#533 Added copy constructor to Regex.

parent 137e9606
No related branches found
No related tags found
No related merge requests found
......@@ -27,10 +27,10 @@
namespace cta { namespace utils {
Regex::Regex(const char * re_str) : m_set(false) {
if (int rc = ::regcomp(&m_re, re_str, REG_EXTENDED)) {
Regex::Regex(const std::string & re_str) : m_reStr(re_str), m_set(false) {
if (int rc = ::regcomp(&m_re, m_reStr.c_str(), REG_EXTENDED)) {
std::string error("Could not compile regular expression: \"");
error += re_str;
error += m_reStr;
error += "\"";
char re_err[1024];
if (::regerror(rc, &m_re, re_err, sizeof (re_err))) {
......@@ -42,6 +42,10 @@ Regex::Regex(const char * re_str) : m_set(false) {
m_set = true;
}
Regex::Regex(const Regex& o) {
Regex(o.m_reStr);
}
Regex::~Regex() {
if (m_set)
::regfree(&m_re);
......
......@@ -29,7 +29,8 @@ namespace cta { namespace utils {
class Regex {
public:
Regex(const char * re_str);
Regex(const std::string & re_str);
Regex(const Regex & o);
virtual ~Regex();
/*!
......@@ -45,6 +46,8 @@ class Regex {
}
private:
// We keep around the string from which the RE was compiled to allow copying.
std::string m_reStr;
regex_t m_re;
bool m_set;
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment