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
00035 class Matcher
00036 {
00037 friend class NFANode;
00038 friend class NFAStartNode;
00039 friend class NFAEndNode;
00040 friend class NFAGroupHeadNode;
00041 friend class NFAGroupLoopNode;
00042 friend class NFAGroupLoopPrologueNode;
00043 friend class NFAGroupTailNode;
00044 friend class NFALookBehindNode;
00045 friend class NFAStartOfLineNode;
00046 friend class NFAEndOfLineNode;
00047 friend class NFAEndOfMatchNode;
00048 friend class NFAReferenceNode;
00049 friend class Pattern;
00050 private:
00058 Matcher(Pattern * pattern, const std::string & text);
00059 protected:
00061 Pattern * pat;
00063 std::string str;
00065 int start;
00067 int * starts;
00069 int * ends;
00071 int * groups;
00073 int * groupIndeces;
00075 int * groupPos;
00077 int lm;
00079 int gc;
00081 int ncgc;
00083 int matchedSomething;
00085 unsigned long flags;
00087 void clearGroups();
00088 public:
00090 const static int MATCH_ENTIRE_STRING;
00091 public:
00093 ~Matcher();
00101 std::string replaceWithGroups(const std::string & str);
00106 unsigned long getFlags() const;
00111 std::string getText() const;
00112
00120 bool matches();
00129 bool findFirstMatch();
00138 bool findNextMatch();
00145 std::vector<std::string> findAll();
00149 void reset();
00154 inline std::string getString() const { return str; }
00159 inline void setString(const std::string & newStr) { str = newStr; reset(); }
00160
00167 int getStartingIndex(const int groupNum = 0) const;
00174 int getEndingIndex(const int groupNum = 0) const;
00183 std::string getGroup(const int groupNum = 0) const;
00190 std::vector<std::string> getGroups(const bool includeGroupZero = 0) const;
00191
00196 int getGroupNum() {return gc;}
00197 };
00198
00199 #endif