00001 #ifndef CLASSLIB_REGEXP_MATCH_H 00002 # define CLASSLIB_REGEXP_MATCH_H 00003 00004 //<<<<<< INCLUDES >>>>>> 00005 00006 # include "classlib/utils/StringList.h" 00007 # include <utility> 00008 # include <string> 00009 # include <vector> 00010 # include <list> 00011 00012 namespace lat { 00013 //<<<<<< PUBLIC DEFINES >>>>>> 00014 //<<<<<< PUBLIC CONSTANTS >>>>>> 00015 //<<<<<< PUBLIC TYPES >>>>>> 00016 //<<<<<< PUBLIC VARIABLES >>>>>> 00017 //<<<<<< PUBLIC FUNCTIONS >>>>>> 00018 //<<<<<< CLASS DECLARATIONS >>>>>> 00019 00020 class RegexpMatch 00021 { 00022 public: 00027 typedef std::pair<int,int> Marker; 00028 00036 typedef std::vector<Marker> MarkerList; 00037 00038 RegexpMatch (void); 00039 RegexpMatch (const RegexpMatch &x); 00040 RegexpMatch &operator= (const RegexpMatch &x); 00041 ~RegexpMatch (void); 00042 00043 // Interface for adding match results 00044 void setCaptures (int n); 00045 void addMatchSet (void); 00046 void addMatchPos (int begin, int end); 00047 void addMatches (const RegexpMatch &match); 00048 00049 // what do matchPos/End/Length/String return when there is no match? 00050 void reset (void); 00051 00052 int numCaptures (void) const; 00053 int numMatchSets (void) const; 00054 int numMatches (void) const; 00055 00056 MarkerList allMatches (void) const; 00057 bool matched (int n = 0) const; 00058 int matchPos (int n = 0) const; 00059 int matchEnd (int n = 0) const; 00060 int matchLength (int n = 0) const; 00061 00062 std::string matchString (const std::string &s, int n = 0) const; 00063 static std::string matchString (const std::string &s, const Marker &m); 00064 StringList matchStrings (const std::string &s) const; 00065 static StringList matchStrings (const std::string &s, const MarkerList &m); 00066 00067 std::string matchString (const char *s, int index = 0) const; 00068 static std::string matchString (const char *s, const Marker &m); 00069 StringList matchStrings (const char *s) const; 00070 static StringList matchStrings (const char *s, const MarkerList &m); 00071 00072 private: 00073 int m_captures; 00074 int m_matches; 00075 MarkerList m_markers; 00076 }; 00077 00078 //<<<<<< INLINE PUBLIC FUNCTIONS >>>>>> 00079 //<<<<<< INLINE MEMBER FUNCTIONS >>>>>> 00080 00081 } // namespace lat 00082 #endif // CLASSLIB_REGEXP_MATCH_H