00001 #ifndef __MATCHER_H__ 00002 #define __MATCHER_H__ 00003 00004 #include <string> 00005 #include <vector> 00006 00007 class Vector; 00008 class NFANode; 00009 class NFAStartNode; 00010 class NFAEndNode; 00011 class NFAGroupHeadNode; 00012 class NFAGroupLoopNode; 00013 class NFAGroupLoopPrologueNode; 00014 class NFAGroupTailNode; 00015 class NFALookBehindNode; 00016 class NFAStartOfLineNode; 00017 class NFAEndOfLineNode; 00018 class NFAEndOfMatchNode; 00019 class NFAReferenceNode; 00020 class Pattern; 00021 00090 class Matcher 00091 { 00092 friend class NFANode; 00093 friend class NFAStartNode; 00094 friend class NFAEndNode; 00095 friend class NFAGroupHeadNode; 00096 friend class NFAGroupLoopNode; 00097 friend class NFAGroupLoopPrologueNode; 00098 friend class NFAGroupTailNode; 00099 friend class NFALookBehindNode; 00100 friend class NFAStartOfLineNode; 00101 friend class NFAEndOfLineNode; 00102 friend class NFAEndOfMatchNode; 00103 friend class NFAReferenceNode; 00104 friend class Pattern; 00105 private: 00113 Matcher(Pattern * pattern, const std::string & text); 00114 protected: 00116 Pattern * pat; 00118 std::string str; 00120 int start; 00122 int * starts; 00124 int * ends; 00126 int * groups; 00128 int * groupIndeces; 00130 int * groupPos; 00132 int lm; 00134 int gc; 00136 int ncgc; 00138 int matchedSomething; 00140 unsigned long flags; 00142 void clearGroups(); 00143 public: 00145 const static int MATCH_ENTIRE_STRING; 00146 public: 00148 ~Matcher(); 00156 std::string replaceWithGroups(const std::string & str); 00161 unsigned long getFlags() const; 00166 std::string getText() const; 00167 00175 bool matches(); 00184 bool findFirstMatch(); 00193 bool findNextMatch(); 00200 std::vector<std::string> findAll(); 00204 void reset(); 00209 inline std::string getString() const { return str; } 00214 inline void setString(const std::string & newStr) { str = newStr; reset(); } 00215 00222 int getStartingIndex(const int groupNum = 0) const; 00229 int getEndingIndex(const int groupNum = 0) const; 00238 std::string getGroup(const int groupNum = 0) const; 00245 std::vector<std::string> getGroups(const bool includeGroupZero = 0) const; 00246 00251 int getGroupNum() {return gc;} 00252 00253 }; 00254 00255 #endif