00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef ROOT_TPRegexp
00013 #define ROOT_TPRegexp
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef ROOT_Rtypes
00030 #include "Rtypes.h"
00031 #endif
00032 #ifndef ROOT_TString
00033 #include "TString.h"
00034 #endif
00035 #ifndef ROOT_TArrayI
00036 #include "TArrayI.h"
00037 #endif
00038
00039 struct PCREPriv_t;
00040
00041
00042 class TPRegexp {
00043
00044 protected:
00045 enum {
00046 kPCRE_GLOBAL = 0x80000000,
00047 kPCRE_OPTIMIZE = 0x40000000,
00048 kPCRE_DEBUG_MSGS = 0x20000000,
00049 kPCRE_INTMASK = 0x0FFF
00050 };
00051
00052 TString fPattern;
00053 PCREPriv_t *fPriv;
00054 UInt_t fPCREOpts;
00055
00056 void Compile();
00057 void Optimize();
00058 UInt_t ParseMods(const TString &mods) const;
00059 Int_t ReplaceSubs(const TString &s, TString &final,
00060 const TString &replacePattern,
00061 Int_t *ovec, Int_t nmatch) const;
00062
00063 Int_t MatchInternal(const TString& s, Int_t start,
00064 Int_t nMaxMatch, TArrayI *pos=0);
00065
00066 Int_t SubstituteInternal(TString &s, const TString &replace,
00067 Int_t start, Int_t nMaxMatch0,
00068 Bool_t doDollarSubst);
00069
00070 public:
00071 TPRegexp();
00072 TPRegexp(const TString &pat);
00073 TPRegexp(const TPRegexp &p);
00074 virtual ~TPRegexp();
00075
00076 Int_t Match(const TString &s, const TString &mods="",
00077 Int_t start=0, Int_t nMaxMatch=10, TArrayI *pos=0);
00078 TObjArray *MatchS(const TString &s, const TString &mods="",
00079 Int_t start=0, Int_t nMaxMatch=10);
00080 Bool_t MatchB(const TString &s, const TString &mods="",
00081 Int_t start=0, Int_t nMaxMatch=10) {
00082 return (Match(s,mods,start,nMaxMatch) > 0); }
00083 Int_t Substitute(TString &s, const TString &replace,
00084 const TString &mods="", Int_t start=0,
00085 Int_t nMatchMax=10);
00086
00087 TString GetPattern() const { return fPattern; }
00088 TString GetModifiers() const;
00089
00090 TPRegexp &operator=(const TPRegexp &p);
00091
00092 ClassDef(TPRegexp,0)
00093 };
00094
00095
00096 class TPMERegexp : protected TPRegexp {
00097
00098 private:
00099 TPMERegexp& operator=(const TPMERegexp&);
00100
00101 protected:
00102 Int_t fNMaxMatches;
00103 Int_t fNMatches;
00104 TArrayI fMarkers;
00105
00106 TString fLastStringMatched;
00107 void *fAddressOfLastString;
00108
00109 Int_t fLastGlobalPosition;
00110
00111 public:
00112 TPMERegexp();
00113 TPMERegexp(const TString& s, const TString& opts = "", Int_t nMatchMax = 10);
00114 TPMERegexp(const TString& s, UInt_t opts, Int_t nMatchMax = 10);
00115 TPMERegexp(const TPMERegexp& r);
00116
00117 virtual ~TPMERegexp() {}
00118
00119 void Reset(const TString& s, const TString& opts = "", Int_t nMatchMax = -1);
00120 void Reset(const TString& s, UInt_t opts, Int_t nMatchMax = -1);
00121
00122 Int_t GetNMaxMatches() const { return fNMaxMatches; }
00123 void SetNMaxMatches(Int_t nm) { fNMaxMatches = nm; }
00124
00125 Int_t GetGlobalPosition() const { return fLastGlobalPosition; }
00126 void AssignGlobalState(const TPMERegexp& re);
00127 void ResetGlobalState();
00128
00129 Int_t Match(const TString& s, UInt_t start = 0);
00130 Int_t Split(const TString& s, Int_t maxfields = 0);
00131 Int_t Substitute(TString& s, const TString& r, Bool_t doDollarSubst=kTRUE);
00132
00133 Int_t NMatches() const { return fNMatches; }
00134 TString operator[](Int_t);
00135
00136 virtual void Print(Option_t* option="");
00137
00138 ClassDef(TPMERegexp, 0);
00139 };
00140
00141
00142 class TStringToken : public TString {
00143
00144 protected:
00145 const TString fFullStr;
00146 TPRegexp fSplitRe;
00147 Bool_t fReturnVoid;
00148 Int_t fPos;
00149
00150 public:
00151 TStringToken(const TString& fullStr, const TString& splitRe, Bool_t retVoid=kFALSE);
00152 virtual ~TStringToken() {}
00153
00154 Bool_t NextToken();
00155 Bool_t AtEnd() const { return fPos >= fFullStr.Length(); }
00156
00157 ClassDef(TStringToken,0)
00158 };
00159
00160 #endif