From f43748e1dd656a4b9c5f2d59ece64618a51efba5 Mon Sep 17 00:00:00 2001 From: Brad King Date: Fri, 16 May 2008 11:06:18 -0400 Subject: ENH: Add assignment operator to KWSys RegularExpression. --- Source/kwsys/RegularExpression.cxx | 32 ++++++++++++++++++++++++++++++++ Source/kwsys/RegularExpression.hxx.in | 5 +++++ 2 files changed, 37 insertions(+) diff --git a/Source/kwsys/RegularExpression.cxx b/Source/kwsys/RegularExpression.cxx index 6d31e39..ac2c9b0 100644 --- a/Source/kwsys/RegularExpression.cxx +++ b/Source/kwsys/RegularExpression.cxx @@ -74,6 +74,38 @@ RegularExpression::RegularExpression (const RegularExpression& rxp) { this->regmlen = rxp.regmlen; // Copy remaining private data } +// operator= -- Copies the given regular expression. +RegularExpression& RegularExpression::operator= (const RegularExpression& rxp) +{ + if ( !rxp.program ) + { + this->program = 0; + return *this; + } + int ind; + this->progsize = rxp.progsize; // Copy regular expression size + this->program = new char[this->progsize]; // Allocate storage + for(ind=this->progsize; ind-- != 0;) // Copy regular expresion + this->program[ind] = rxp.program[ind]; + this->startp[0] = rxp.startp[0]; // Copy pointers into last + this->endp[0] = rxp.endp[0]; // Successful "find" operation + this->regmust = rxp.regmust; // Copy field + if (rxp.regmust != 0) { + char* dum = rxp.program; + ind = 0; + while (dum != rxp.regmust) { + ++dum; + ++ind; + } + this->regmust = this->program + ind; + } + this->regstart = rxp.regstart; // Copy starting index + this->reganch = rxp.reganch; // Copy remaining private data + this->regmlen = rxp.regmlen; // Copy remaining private data + + return *this; +} + // operator== -- Returns true if two regular expressions have the same // compiled program for pattern matching. bool RegularExpression::operator== (const RegularExpression& rxp) const { diff --git a/Source/kwsys/RegularExpression.hxx.in b/Source/kwsys/RegularExpression.hxx.in index 5780c21..a681e11 100644 --- a/Source/kwsys/RegularExpression.hxx.in +++ b/Source/kwsys/RegularExpression.hxx.in @@ -234,6 +234,11 @@ public: inline kwsys_stl::string::size_type end() const; /** + * Copy the given regular expression. + */ + RegularExpression& operator= (const RegularExpression& rxp); + + /** * Returns true if two regular expressions have the same * compiled program for pattern matching. */ -- cgit v0.12