40 const unsigned TRegexp::fgMaxpat = 2048;
51 TRegexp::TRegexp(
const char *re, Bool_t wildcard)
54 GenPattern(MakeWildcard(re));
62 TRegexp::TRegexp(
const TString& re)
64 GenPattern(re.Data());
70 TRegexp::TRegexp(
const TRegexp& r)
86 TRegexp& TRegexp::operator=(
const TRegexp& r)
98 TRegexp& TRegexp::operator=(
const char *str)
108 TRegexp& TRegexp::operator=(
const TString &str)
111 GenPattern(str.Data());
118 void TRegexp::GenPattern(
const char *str)
120 fPattern =
new Pattern_t[fgMaxpat];
121 int error = ::Makepat(str, fPattern, fgMaxpat);
122 fStat = (error < 3) ? (EStatVal) error : kToolong;
128 void TRegexp::CopyPattern(
const TRegexp& r)
130 fPattern =
new Pattern_t[fgMaxpat];
131 memcpy(fPattern, r.fPattern, fgMaxpat *
sizeof(Pattern_t));
145 const char *TRegexp::MakeWildcard(
const char *re)
147 TTHREAD_TLS_ARRAY(
char,fgMaxpat,buf);
150 int len = strlen(re);
155 for (
int i = 0; i < len; i++) {
156 if ((
unsigned)slen > fgMaxpat - 10) {
157 Error(
"MakeWildcard",
"regexp too large");
160 if (i == 0 && re[i] !=
'^') {
167 const char *wc =
"[^/]";
170 const char *wc =
"[^\\/:]";
183 const char *wc =
"[^/]";
186 const char *wc =
"[^\\/:]";
195 if (i == len-1 && re[i] !=
'$') {
209 Ssiz_t TRegexp::Index(
const TString&
string, Ssiz_t* len, Ssiz_t i)
const
212 Error(
"TRegexp::Index",
"Bad Regular Expression");
215 const char* s =
string.Data();
216 Ssiz_t slen =
string.Length();
217 if (slen < i)
return kNPOS;
218 const char* endp = ::Matchs(s+i, slen-i, fPattern, &startp);
220 *len = endp - startp;
231 TRegexp::EStatVal TRegexp::Status()
233 EStatVal temp = fStat;
250 Ssiz_t TString::Index(
const TRegexp& r, Ssiz_t start)
const
253 return r.Index(*
this, &len, start);
261 Ssiz_t TString::Index(
const TRegexp& r, Ssiz_t* extent, Ssiz_t start)
const
263 return r.Index(*
this, extent, start);
269 TSubString TString::operator()(
const TRegexp& r, Ssiz_t start)
const
272 Ssiz_t begin = Index(r, &len, start);
273 return TSubString(*
this, begin, len);
279 TSubString TString::operator()(
const TRegexp& r)
const
303 Bool_t TString::Tokenize(TString &tok, Ssiz_t &from,
const char *delim)
const
305 Bool_t found = kFALSE;
311 Int_t len = Length();
312 if (len <= 0 || from > (len - 1) || from < 0)
316 TString rdelim(delim);
317 if(rdelim.Length() == 1) {
318 rdelim =
"[" + rdelim +
"]+";
324 Int_t pos = Index(rg, &ext, from);
327 if (pos == kNPOS || pos > from) {
328 Ssiz_t last = (pos != kNPOS) ? (pos - 1) : len;
329 tok = (*this)(from, last-from+1);
343 from = (from < len) ? from : len;