***********************
** FILE NAME : regex.cpp
** SYSTEM NAME : Andromeda X-Windows Encapsulation
-** VERSION NUMBER : $Revision: 1.1 $
+** VERSION NUMBER : $Revision: 1.3 $
**
** DESCRIPTION : regex class implementation.
**
********************************
** ORIGINAL AUTHOR : Arjen Baart - arjen@andromeda.nl
** CREATION DATE : Feb 23, 2001
-** LAST UPDATE : Feb 23, 2001
+** LAST UPDATE : Mar 31, 2010
** MODIFICATIONS :
**************************************************************************/
/*****************************
$Log: regex.cpp,v $
- Revision 1.1 2002-07-25 08:01:27 arjen
+ Revision 1.3 2007/05/04 13:56:05 arjen
+ Added a copy contructor to the regex class. This prevents multiple frees in the destructor.
+
+ Revision 1.2 2002/09/28 06:45:51 arjen
+ New feature: subtring selection by regular expression.
+ Bugfix: use the std: namespace for STL classes istream and ostream
+
+ Revision 1.1 2002/07/25 08:01:27 arjen
First checkin, AXE release 0.2
*****************************/
-static const char RCSID[] = "$Id: regex.cpp,v 1.1 2002-07-25 08:01:27 arjen Exp $";
+static const char RCSID[] = "$Id: regex.cpp,v 1.3 2007/05/04 13:56:05 arjen Exp $";
#include <stdio.h>
#include <ctype.h>
regex::regex(const String ®)
{
- regcomp (&expression, reg.p->s, REG_EXTENDED);
+ original = reg;
+ int error = regcomp (&expression, reg.p->s, REG_EXTENDED);
}
regex::regex(const char *reg)
{
- regcomp (&expression, reg, REG_EXTENDED);
+ original = reg;
+ int error = regcomp (&expression, reg, REG_EXTENDED);
+}
+
+regex::regex(const regex & reg)
+{
+ original = reg.original;
+ int error = regcomp (&expression, reg.original, REG_EXTENDED);
}
regex::~regex()
regfree(&expression);
}
+regex& regex::operator=(const regex& x)
+{
+ original = x.original;
+ int error = regcomp (&expression, x.original, REG_EXTENDED);
+
+ return *this;
+}
bool operator == (const String &s, const regex &r)
{
{
return regexec(&r.expression, s.p->s, 0, 0, 0) == 0;
}
+
+substring String::operator()(const regex &r)
+{
+ substring sub;
+ regmatch_t match;
+
+ sub.str = this;
+ sub.start = 0;
+ sub.len = 0;
+
+ if (regexec(&r.expression, p->s, 1, &match, 0) == 0)
+ {
+ sub.start = match.rm_so;
+ sub.len = match.rm_eo - match.rm_so;
+ }
+
+ return sub;
+}
+