New feature: subtring selection by regular expression.
[AXE.git] / src / regex.cpp
index e3b4311..025ff40 100644 (file)
@@ -5,7 +5,7 @@
 ***********************
 **      FILE NAME      : regex.cpp
 **      SYSTEM NAME    : Andromeda X-Windows Encapsulation
-**      VERSION NUMBER : $Revision: 1.1 $
+**      VERSION NUMBER : $Revision: 1.2 $
 **
 **  DESCRIPTION      :  regex class implementation.
 **
 
 /*****************************
    $Log: regex.cpp,v $
-   Revision 1.1  2002-07-25 08:01:27  arjen
+   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.2 2002-09-28 06:45:51 arjen Exp $";
 
 #include <stdio.h>
 #include <ctype.h>
@@ -60,3 +64,22 @@ bool operator == (const regex &r, const String &s)
 {
    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;
+}
+