00001
00002
00003 #ifndef MuscleStringMatcher_h
00004 #define MuscleStringMatcher_h
00005
00006 #include <sys/types.h>
00007 #include "util/RefCount.h"
00008 #include "util/String.h"
00009
00010 #ifdef __BEOS__
00011 # if __POWERPC__
00012 # include "regex/regex/regex.h"
00013 # else
00014 # include <regex.h>
00015 # endif
00016 #else
00017 # ifdef WIN32
00018 # include "regex/regex/regex.h"
00019 # else
00020 # include <regex.h>
00021 # endif
00022 #endif
00023
00024 BEGIN_NAMESPACE(muscle);
00025
00027 class StringMatcher : public RefCountable
00028 {
00029 public:
00031 StringMatcher();
00032
00034 StringMatcher(const String & matchString, bool isSimpleFormat = true);
00035
00037 ~StringMatcher();
00038
00053 status_t SetPattern(const String & expression, bool isSimpleFormat=true);
00054
00056 const String & GetPattern() const {return _pattern;}
00057
00061 bool IsPatternUnique() const {return (_hasRegexTokens == false)&&(_negate == false)&&(_rangeMin == MUSCLE_NO_LIMIT);}
00062
00067 bool Match(const char * const matchString) const;
00068
00070 inline bool Match(const String & matchString) const {return Match(matchString());}
00071
00079 void SetNegate(bool negate) {_negate = negate;}
00080
00082 bool IsNegate() const {return _negate;}
00083
00084 private:
00085 bool _regExpValid;
00086 bool _negate;
00087 bool _hasRegexTokens;
00088 String _pattern;
00089 regex_t _regExp;
00090 uint32 _rangeMin;
00091 uint32 _rangeMax;
00092 };
00093
00094 typedef Ref<StringMatcher> StringMatcherRef;
00095
00100 StringMatcherRef::ItemPool * GetStringMatcherPool();
00101
00102
00103
00110 void EscapeRegexTokens(String & str, const char * optTokens = NULL);
00111
00115 void RemoveEscapeChars(String & str);
00116
00121 bool HasRegexTokens(const char * str);
00122
00124 inline bool HasRegexTokens(const String & str) {return HasRegexTokens(str());}
00125
00132 bool IsRegexToken(char c, bool isFirstCharInString);
00133
00140 bool MakeRegexCaseInsensitive(String & str);
00141
00142 END_NAMESPACE(muscle);
00143
00144
00145 #endif