diff options
author | Brad King <brad.king@kitware.com> | 2008-05-16 11:06:18 -0400 |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2008-05-16 11:06:18 -0400 |
commit | f43748e1dd656a4b9c5f2d59ece64618a51efba5 (patch) | |
tree | ada810555a08b905bac22d546f07ade1ed944369 | |
parent | b18b370aab5cfc51d5aaac5aa90f14b86642da78 (diff) | |
download | cmake-f43748e1dd656a4b9c5f2d59ece64618a51efba5.tar.gz |
ENH: Add assignment operator to KWSys RegularExpression.
-rw-r--r-- | Source/kwsys/RegularExpression.cxx | 32 | ||||
-rw-r--r-- | Source/kwsys/RegularExpression.hxx.in | 5 |
2 files changed, 37 insertions, 0 deletions
diff --git a/Source/kwsys/RegularExpression.cxx b/Source/kwsys/RegularExpression.cxx index 6d31e39c71..ac2c9b0676 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 5780c21e9a..a681e110e8 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. */ |