CrystalSpace

Public API Reference

csutil/regexp.h
Go to the documentation of this file.
00001 /*
00002     Copyright (C) 2004 by Frank Richter
00003 
00004     This library is free software; you can redistribute it and/or
00005     modify it under the terms of the GNU Library General Public
00006     License as published by the Free Software Foundation; either
00007     version 2 of the License, or (at your option) any later version.
00008 
00009     This library is distributed in the hope that it will be useful,
00010     but WITHOUT ANY WARRANTY; without even the implied warranty of
00011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012     Library General Public License for more details.
00013 
00014     You should have received a copy of the GNU Library General Public
00015     License along with this library; if not, write to the Free
00016     Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00017 */
00018 
00019 #ifndef __CS_UTIL_REGEXP_H__
00020 #define __CS_UTIL_REGEXP_H__
00021 
00026 #include "csextern.h"
00027 #include "csutil/array.h"
00028 
00029 // Include system's (if available) ...
00030 #ifdef CS_HAVE_REGEX
00031   #include <regex.h>
00032 #else
00033 // ... resp. the one included with CS.
00034   #if (defined(CS_COMPILER_MSVC) || defined(CS_COMPILER_BCC)) && \
00035       !defined(__STDC__)
00036     #define __STDC__  1
00037     #define __STDC__DEFINED
00038   #endif
00039   #include "generic/regex.h"
00040   #ifdef __STDC__DEFINED
00041     #undef __STDC__
00042   #endif
00043 #endif
00044 
00048 enum csRegExpMatchError
00049 {
00051   csrxNoError,
00053   csrxNoMatch,
00059   csrxBadBraces,
00063   csrxBadPattern,
00068   csrxBadRepetition,
00073   csrxErrCollate,
00077   csrxErrCharType,
00081   csrxErrEscape,
00085   csrxErrSubReg,
00089   csrxErrBrackets,
00094   csrxErrParentheses,
00098   csrxErrBraces,
00102   csrxErrRange,
00106   csrxErrSpace,
00110   csrxErrUnknown
00111 };
00112 
00116 enum csRegExpMatchFlags
00117 {
00121   csrxIgnoreCase = 1,
00130   csrxNewLine = 2,
00136   csrxNotBOL = 4,
00141   csrxNotEOL = 8
00142 };
00143 
00147 struct CS_CRYSTALSPACE_EXPORT csRegExpMatch
00148 {
00150   size_t startOffset;
00155   size_t endOffset;
00156 };
00157 
00169 class CS_CRYSTALSPACE_EXPORT csRegExpMatcher : 
00170   public CS::Memory::CustomAllocated
00171 {
00172   regex_t regex;
00173   char* pattern;
00174   int compiledFlags;
00175 
00176   bool regexpSetup : 1;
00177   bool extendedRE : 1;
00178   csRegExpMatchError compileError : 30;
00179   
00180   bool Compile (int flags, bool nosub);
00181 
00182 public:
00189   csRegExpMatcher (const char* pattern, bool extendedRE = false);
00190 
00192   csRegExpMatcher (const csRegExpMatcher& other);
00193 
00195   ~csRegExpMatcher ();
00196   
00198   csRegExpMatcher& operator= (const csRegExpMatcher &other);
00199 
00209   csRegExpMatchError Match (const char* string, int flags = 0);
00210 
00222   csRegExpMatchError Match (const char* string, 
00223     csArray<csRegExpMatch>& matches, int flags = 0);
00224 };
00225 
00226 #endif // __CS_UTIL_REGEXP_H__

Generated for Crystal Space 2.0 by doxygen 1.7.6.1