Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
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
00030 #ifdef CS_HAVE_REGEX
00031 #include <regex.h>
00032 #else
00033
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__