ENH: Add assignment operator to KWSys RegularExpression.
This commit is contained in:
parent
b18b370aab
commit
f43748e1dd
|
@ -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 {
|
||||
|
|
|
@ -233,6 +233,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.
|
||||
|
|
Loading…
Reference in New Issue