RegExp.h++

Go to the documentation of this file.
00001 /* ---------------------------------------------------------------------------
00002    commonc++ - A C++ Common Class Library
00003    Copyright (C) 2005-2012  Mark A Lindner
00004 
00005    This file is part of commonc++.
00006 
00007    This library is free software; you can redistribute it and/or
00008    modify it under the terms of the GNU Library General Public
00009    License as published by the Free Software Foundation; either
00010    version 2 of the License, or (at your option) any later version.
00011 
00012    This library is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015    Library General Public License for more details.
00016 
00017    You should have received a copy of the GNU Library General Public
00018    License along with this library; if not, write to the Free
00019    Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00020    ---------------------------------------------------------------------------
00021 */
00022 
00023 #ifndef __ccxx_RegExp_hxx
00024 #define __ccxx_RegExp_hxx
00025 
00026 #include <commonc++/Common.h++>
00027 #include <commonc++/ParseException.h++>
00028 #include <commonc++/String.h++>
00029 
00030 #include <sys/types.h>
00031 
00032 namespace ccxx {
00033 
00040 class COMMONCPP_API RegExpMatch
00041 {
00042   friend class RegExp;
00043 
00044   public:
00045 
00047   RegExpMatch()
00048     : rm_so(-1), rm_eo(-1)
00049   { }
00050 
00052   inline bool isValid() const throw()
00053   { return(rm_so >= 0); }
00054 
00056   inline uint_t getStartIndex() const throw()
00057   { return(rm_so >= 0 ? rm_so : 0); }
00058 
00062   inline uint_t getEndIndex() const throw()
00063   { return((rm_eo >= 0) && (rm_so >= 0) ? rm_eo : 0); }
00064 
00065   private:
00066 
00067   int rm_so;
00068   int rm_eo;
00069 };
00070 
00076 class COMMONCPP_API RegExp
00077 {
00078   public:
00079 
00081   RegExp() throw();
00082 
00084   RegExp(const RegExp& other) throw(ParseException);
00085 
00087   ~RegExp() throw();
00088 
00096   void setPattern(const char *pattern, bool caseInsensitive = false)
00097     throw(ParseException);
00098 
00106   void setPattern(const String &pattern, bool caseInsensitive = false)
00107     throw(ParseException);
00108 
00110   inline String getPattern() const
00111   { return(_pattern); }
00112 
00114   inline String toString() const
00115   { return(getPattern()); }
00116 
00123   bool match(const char *text) const throw();
00124 
00131   bool match(const String &text) const throw();
00132 
00141   bool match(const char *text, RegExpMatch matches[], int numMatches) const
00142     throw();
00143 
00152   bool match(const String &text, RegExpMatch matches[], int numMatches)
00153     const throw();
00154 
00156   RegExp& operator=(const RegExp &other);
00157 
00159   inline bool isNull() const throw()
00160   { return(_pattern.isNull()); }
00161 
00163   inline bool operator!() const throw()
00164   { return(_pattern.isNull()); }
00165 
00171   static String escapeMeta(const String &text);
00172 
00173   private:
00174 
00175   String _pattern;
00176   struct
00177   {
00178     void *re_pcre;
00179     size_t re_nsub;
00180     size_t re_erroffset;
00181   } _regex;
00182   bool _compiled;
00183 };
00184 
00185 }; // namespace ccxx
00186 
00187 #endif // __ccxx_RegExp_hxx
00188 
00189 /* end of header file */
Generated on Sat Nov 26 16:49:07 2011 for libcommonc++ by  doxygen 1.6.3