Main Page   Namespace List   Compound List   File List   Compound Members   File Members  

pcre++.cc

Go to the documentation of this file.
00001 /*
00002  *
00003  *  This file  is part of the PCRE++ Class Library.
00004  *
00005  *  By  accessing  this software,  PCRE++, you  are  duly informed
00006  *  of and agree to be  bound  by the  conditions  described below
00007  *  in this notice:
00008  *
00009  *  This software product,  PCRE++,  is developed by Thomas Linden
00010  *  and copyrighted (C) 2002-2003 by Thomas Linden,with all rights 
00011  *  reserved.
00012  *
00013  *  There  is no charge for PCRE++ software.  You can redistribute
00014  *  it and/or modify it under the terms of the GNU  Lesser General
00015  *  Public License, which is incorporated by reference herein.
00016  *
00017  *  PCRE++ is distributed WITHOUT ANY WARRANTY, IMPLIED OR EXPRESS,
00018  *  OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE or that
00019  *  the use of it will not infringe on any third party's intellec-
00020  *  tual property rights.
00021  *
00022  *  You should have received a copy of the GNU Lesser General Public
00023  *  License along with PCRE++.  Copies can also be obtained from:
00024  *
00025  *    http://www.gnu.org/licenses/lgpl.txt
00026  *
00027  *  or by writing to:
00028  *
00029  *  Free Software Foundation, Inc.
00030  *  59 Temple Place, Suite 330
00031  *  Boston, MA 02111-1307
00032  *  USA
00033  *
00034  *  Or contact:
00035  *
00036  *   "Thomas Linden" <tom@daemon.de>
00037  *
00038  *
00039  */
00040 
00041 
00042 #include "pcre++.h"
00043 
00044 using namespace std;
00045 
00046 /*
00047  * CONSTRUCTORS and stuff
00048  */
00049 Pcre::Pcre(const string& expression) {
00050   _expression   = expression;
00051   _flags        = 0;
00052   case_t = global_t = false;
00053   zero();
00054   Compile(0);
00055 }
00056 
00057 Pcre::Pcre(const string& expression, const string& flags) {
00058   _expression   = expression;
00059   unsigned int FLAG = 0;
00060 
00061   for(unsigned int flag=0; flag<flags.length(); flag++) {
00062     switch(flags[flag]) {
00063     case 'i': FLAG |= PCRE_CASELESS;  case_t = true;   break;
00064     case 'm': FLAG |= PCRE_MULTILINE;                  break;
00065     case 's': FLAG |= PCRE_DOTALL;                     break;
00066     case 'x': FLAG |= PCRE_EXTENDED;                   break;
00067     case 'g':                         global_t = true; break;
00068     }
00069   }
00070 
00071   _flags = FLAG;
00072 
00073   zero();
00074   Compile(FLAG);
00075 }
00076 
00077 Pcre::Pcre(const Pcre &P) {
00078   _expression = P._expression;
00079   _flags      = P._flags;
00080   case_t      = P.case_t;
00081   global_t    = P.global_t;
00082   zero();
00083   Compile(_flags);
00084 }
00085 
00086 Pcre::Pcre() {
00087   zero();
00088 }
00089 
00090 
00091 
00092 
00093 
00094 
00095 
00096 /*
00097  * Destructor
00098  */
00099 Pcre::~Pcre() {
00100   /* avoid deleting of uninitialized pointers */
00101   if (p_pcre != NULL) {
00102     pcre_free(p_pcre);
00103   }
00104   if (p_pcre_extra != NULL) {
00105     pcre_free(p_pcre_extra);
00106   }
00107   if(sub_vec != NULL) {
00108     delete[] sub_vec;
00109   }
00110   if(num_matches > 0) {
00111     delete resultset;
00112   }
00113 }
00114 
00115 
00116 
00117 
00118 /*
00119  * operator= definitions
00120  */
00121 const Pcre& Pcre::operator = (const string& expression) {
00122   /* reset the object and re-intialize it */
00123   reset();
00124   _expression = expression;
00125   _flags      = 0;
00126   case_t = global_t = false;
00127   Compile(0);
00128   return *this;
00129 }
00130 
00131 
00132 const Pcre& Pcre::operator = (const Pcre &P) {
00133   reset();
00134   _expression = P._expression;
00135   _flags      = P._flags;
00136   case_t      = P.case_t;
00137   global_t    = P.global_t;
00138   zero();
00139   Compile(_flags);
00140   return *this;
00141 }
00142 
00143 
00144 
00145 
00146 
00147 
00148 /*
00149  * mem resetting methods
00150  */
00151 void Pcre::zero() {
00152   /* what happens if p_pcre is already allocated? hm ... */
00153   p_pcre_extra = NULL;
00154   p_pcre       = NULL;
00155   sub_vec      = NULL;
00156   resultset    = NULL;
00157   err_str      = NULL;
00158   num_matches  = -1;
00159 }
00160 
00161 void Pcre::reset() {
00162   did_match   = false;
00163   num_matches = -1;
00164 }
00165 
00166 
00167 

Generated on Wed Jun 25 00:39:01 2003 for PCRE++ by doxygen1.3-rc3