00001
00030
00031 #ifndef CLDAQ__TREGULAREXPRESSION_HH
00032 #define CLDAQ__TREGULAREXPRESSION_HH
00033
00034 #include "Tglobals.h"
00035
00036
00056 class TRegularExpression
00057 {
00058
00059 public:
00060
00061
00062
00063
00064
00065
00066
00067
00068 enum { DEFAULT = REG_EXTENDED|REG_NEWLINE, IOPTION = DEFAULT|REG_ICASE };
00069
00070 private:
00071 Tstring thePattern;
00072 Tint theOption;
00073 Tint theNumberOfSubMatches;
00074 Tregex_t* theCompiledPattern;
00075 Tregmatch_t* theMatch;
00076 Tregmatch_t* theSubMatch;
00077
00078 public:
00079 TRegularExpression( const Tstring& pattern, Tint option = DEFAULT );
00080 TRegularExpression( Tint option = DEFAULT, const Tstring& pattern = "" );
00081 TRegularExpression( const TRegularExpression& right );
00082 ~TRegularExpression();
00083
00084 public:
00085 const TRegularExpression& operator=( const TRegularExpression& right );
00086 const TRegularExpression& operator=( const Tstring& right );
00087 Tbool operator==( const Tstring& right );
00088 Tbool operator!=( const Tstring& right );
00089
00090 public:
00091 Tvoid Compile();
00092 Tint Index( const Tstring& source, Tint pos = 0 );
00093 TintList Indexes( const Tstring& source, Tint pos = 0 );
00094 Tint Size( const Tstring& source, Tint pos = 0 );
00095 TintList Sizes( const Tstring& source, Tint pos = 0 );
00096 Tstring MatchString( const Tstring& source, Tint pos = 0 );
00097 TstringList MatchStrings( const Tstring& source, Tint pos = 0 );
00098 Tbool IsMatch( const Tstring& source, Tint pos = 0 );
00099 Tint GetNumberOfMatches( const Tstring& source, Tint pos = 0 );
00100 Tstring Substitute( const Tstring& source, const Tstring& substr = "", Tint pos = 0 );
00101 Tstring SubstituteAll( const Tstring& source, const Tstring& substr = "", Tint pos = 0 );
00102 TstringList Split( const Tstring& source, Tint pos = 0 );
00103 TstringList Split( const Tstring& pattern, const Tstring& source, Tint pos = 0 );
00104 TstringList Split( const TRegularExpression& regex, const Tstring& source, Tint pos = 0 );
00105 Tstring GetSubMatch( Tint index, const Tstring& source, Tint pos = 0 );
00106 TstringList GetSubMatch( const Tstring& source, Tint pos = 0 );
00107
00108 public:
00109 const Tstring& GetPattern() const;
00110 Tint GetOption() const;
00111 Tint GetNumberOfSubMatches() const;
00112 const Tregex_t* GetCompiledPattern() const;
00113 const Tregmatch_t* GetMatch() const;
00114 const Tregmatch_t* GetSubMatch() const;
00115 Tvoid SetPattern( const Tstring& pattern );
00116 Tvoid SetOption( Tint option = DEFAULT );
00117 Tvoid IgnoreCase( Tbool stat = Ttrue );
00118
00119 private:
00120 Tvoid free();
00121 Tint execute( const Tstring& source, Tint pos );
00122
00123 #ifdef __CLDAQ_ROOT_DLL
00124 ClassDef(TRegularExpression,0)
00125 #endif
00126
00127 };
00128
00129 inline const Tstring& TRegularExpression::GetPattern() const
00130 {
00131 return thePattern;
00132 }
00133
00134 inline Tint TRegularExpression::GetOption() const
00135 {
00136 return theOption;
00137 }
00138
00139 inline Tint TRegularExpression::GetNumberOfSubMatches() const
00140 {
00141 return theNumberOfSubMatches;
00142 }
00143
00144 inline const Tregex_t* TRegularExpression::GetCompiledPattern() const
00145 {
00146 return theCompiledPattern;
00147 }
00148
00149 inline const Tregmatch_t* TRegularExpression::GetMatch() const
00150 {
00151 return theMatch;
00152 }
00153
00154 inline const Tregmatch_t* TRegularExpression::GetSubMatch() const
00155 {
00156 return theSubMatch;
00157 }
00158
00159 inline Tvoid TRegularExpression::SetPattern( const Tstring& pattern )
00160 {
00161 thePattern = pattern;
00162 Compile();
00163 return;
00164 }
00165
00166 inline Tvoid TRegularExpression::SetOption( Tint option )
00167 {
00168 theOption = option;
00169 Compile();
00170 return;
00171 }
00172
00173 inline Tvoid TRegularExpression::IgnoreCase( Tbool stat )
00174 {
00175 Tint option = theOption;
00176 if ( stat == Ttrue ) {
00177 option |= REG_ICASE;
00178 } else {
00179 option &= ~REG_ICASE;
00180 }
00181 SetOption( option );
00182 return;
00183 }
00184
00185 #endif