FXRex.h

Go to the documentation of this file.
00001 /********************************************************************************
00002 *                                                                               *
00003 *                 R e g u l a r   E x p r e s s i o n   C l a s s               *
00004 *                                                                               *
00005 *********************************************************************************
00006 * Copyright (C) 1999,2006 by Jeroen van der Zijp.   All Rights Reserved.        *
00007 *********************************************************************************
00008 * This library is free software; you can redistribute it and/or                 *
00009 * modify it under the terms of the GNU Lesser General Public                    *
00010 * License as published by the Free Software Foundation; either                  *
00011 * version 2.1 of the License, or (at your option) any later version.            *
00012 *                                                                               *
00013 * This library is distributed in the hope that it will be useful,               *
00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of                *
00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU             *
00016 * Lesser General Public License for more details.                               *
00017 *                                                                               *
00018 * You should have received a copy of the GNU Lesser General Public              *
00019 * License along with this library; if not, write to the Free Software           *
00020 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.    *
00021 *********************************************************************************
00022 * $Id: FXRex.h,v 1.53 2006/01/22 17:58:09 fox Exp $                             *
00023 ********************************************************************************/
00024 #ifndef FXREX_H
00025 #define FXREX_H
00026 
00027 #include "fxdefs.h"
00028 
00029 namespace FX {
00030 
00031 
00033 enum FXRexError {
00034   REGERR_OK,
00035   REGERR_EMPTY,             
00036   REGERR_PAREN,             
00037   REGERR_BRACK,             
00038   REGERR_BRACE,             
00039   REGERR_RANGE,             
00040   REGERR_ESC,               
00041   REGERR_COUNT,             
00042   REGERR_NOATOM,            
00043   REGERR_REPEAT,            
00044   REGERR_BACKREF,           
00045   REGERR_CLASS,             
00046   REGERR_COMPLEX,           
00047   REGERR_MEMORY,            
00048   REGERR_TOKEN              
00049   };
00050 
00051 
00053 enum {
00054   REX_NORMAL    = 0,        
00055   REX_CAPTURE   = 1,        
00056   REX_ICASE     = 2,        
00057   REX_NEWLINE   = 4,        
00058   REX_VERBATIM  = 8,        
00059   REX_SYNTAX    = 16        
00060   };
00061 
00062 
00064 enum {
00065   REX_FORWARD   = 0,        
00066   REX_BACKWARD  = 32,       
00067   REX_NOT_BOL   = 64,       
00068   REX_NOT_EOL   = 128,      
00069   REX_NOT_EMPTY = 256       
00070   };
00071 
00072 
00100 class FXAPI FXRex {
00101 private:
00102   FXint *code;
00103 private:
00104   static const FXchar *const errors[];
00105   static const FXint fallback[];
00106 public:
00107 
00109   FXRex():code((FXint*)fallback){}
00110 
00112   FXRex(const FXRex& orig);
00113 
00115   FXRex(const FXchar* pattern,FXint mode=REX_NORMAL,FXRexError* error=NULL);
00116 
00118   FXRex(const FXString& pattern,FXint mode=REX_NORMAL,FXRexError* error=NULL);
00119 
00121   FXRex& operator=(const FXRex& orig);
00122 
00128   bool empty() const { return (code==fallback); }
00129 
00131   FXRexError parse(const FXchar* pattern,FXint mode=REX_NORMAL);
00132 
00134   FXRexError parse(const FXString& pattern,FXint mode=REX_NORMAL);
00135 
00143   bool match(const FXchar* string,FXint len,FXint* beg=NULL,FXint* end=NULL,FXint mode=REX_FORWARD,FXint npar=1,FXint fm=0,FXint to=2147483647) const;
00144 
00146   bool match(const FXString& string,FXint* beg=NULL,FXint* end=NULL,FXint mode=REX_FORWARD,FXint npar=1,FXint fm=0,FXint to=2147483647) const;
00147 
00155   static FXString substitute(const FXchar* string,FXint len,FXint* beg,FXint* end,const FXString& replace,FXint npar=1);
00156 
00158   static FXString substitute(const FXString& string,FXint* beg,FXint* end,const FXString& replace,FXint npar=1);
00159 
00161   static const FXchar* getError(FXRexError err){ return errors[err]; }
00162 
00164   bool operator==(const FXRex& rex) const;
00165   bool operator!=(const FXRex& rex) const;
00166 
00168   friend FXAPI FXStream& operator<<(FXStream& store,const FXRex& s);
00169   friend FXAPI FXStream& operator>>(FXStream& store,FXRex& s);
00170 
00172  ~FXRex();
00173   };
00174 
00175 
00176 extern FXAPI FXStream& operator<<(FXStream& store,const FXRex& s);
00177 extern FXAPI FXStream& operator>>(FXStream& store,FXRex& s);
00178 
00179 }
00180 
00181 #endif

(C) 2002-2009 Niall Douglas. Some parts (C) to assorted authors.
Generated on Fri Nov 20 18:31:24 2009 for TnFOX by doxygen v1.4.7