32#define PCRE2_CODE_UNIT_WIDTH 8
34#define PCRE_CASELESS PCRE2_CASELESS
35#define PCRE_MULTILINE PCRE2_MULTILINE
36#define PCRE_DOTALL PCRE2_DOTALL
37#define PCRE_EXTENDED PCRE2_EXTENDED
38#define PCRE_ERROR_NOMATCH PCRE2_ERROR_NOMATCH
171 const char *
m = modStr;
178 opts |= PCRE_CASELESS;
181 opts |= PCRE_MULTILINE;
190 opts |= PCRE_EXTENDED;
196 Error(
"ParseMods",
"illegal pattern modifier: %c", *
m);
213 if (
fPCREOpts & PCRE_CASELESS) ret +=
'i';
214 if (
fPCREOpts & PCRE_MULTILINE) ret +=
'm';
216 if (
fPCREOpts & PCRE_EXTENDED) ret +=
'x';
244 &errcode, &patIndex,
nullptr);
249 &errstr, &patIndex,
nullptr);
254 PCRE2_UCHAR errstr[256];
255 pcre2_get_error_message(errcode, errstr, 256);
258 throw std::runtime_error
259 (
TString::Format(
"TPRegexp::Compile() compilation of TPRegexp(%s) failed at: %d because %s",
262 Error(
"Compile",
"compilation of TPRegexp(%s) failed at: %d because %s",
291 Error(
"Optimize",
"Optimization of TPRegexp(%s) failed: %s",
305 const char *
p = replacePattern;
309 while (state != -1) {
323 }
else if (!isdigit(
p[1])) {
324 Error(
"ReplaceSubs",
"badly formed replacement pattern: %s",
325 replacePattern.
Data());
336 Info(
"ReplaceSubs",
"PREGEX appending substr #%d", subnum);
337 if (subnum < 0 || subnum > nrMatch-1) {
338 Error(
"ReplaceSubs",
"bad string number: %d",subnum);
340 const TString subStr = s(offVec[2*subnum],offVec[2*subnum+1]-offVec[2*subnum]);
362 pcre2_match_data *match_data;
363 match_data = pcre2_match_data_create_from_pattern(
fPriv->
fPCRE,
nullptr);
366 match_data,
nullptr);
371 offVec, 3*nMaxMatch);
374 if (nrMatch == PCRE_ERROR_NOMATCH)
376 else if (nrMatch <= 0) {
377 Error(
"Match",
"pcre_exec error = %d", nrMatch);
379 pcre2_match_data_free(match_data);
387 PCRE2_SIZE *oVec = pcre2_get_ovector_pointer(match_data);
388 for (
int i = 0; i < 2 * nrMatch; ++i)
391 pos->
Set(2*nrMatch, offVec);
395 pcre2_match_data_free(match_data);
445 Int_t nrMatch =
Match(s, mods, start, nMaxMatch, &pos);
450 for (
Int_t i = 0; i < nrMatch; i++) {
451 Int_t startp = pos[2*i];
452 Int_t stopp = pos[2*i+1];
453 if (startp >= 0 && stopp >= 0) {
454 const TString subStr = s(pos[2*i], pos[2*i+1]-pos[2*i]);
469 Bool_t doDollarSubst)
const
479 pcre2_match_data *match_data;
480 match_data = pcre2_match_data_create_from_pattern(
fPriv->
fPCRE,
nullptr);
490 match_data,
nullptr);
494 offVec, 3*nMaxMatch);
497 if (nrMatch == PCRE_ERROR_NOMATCH) {
499 }
else if (nrMatch <= 0) {
500 Error(
"Substitute",
"pcre_exec error = %d", nrMatch);
505 PCRE2_SIZE *oVec = pcre2_get_ovector_pointer(match_data);
506 for (
int i = 0; i < 2 * nrMatch; ++i)
511 if (last <= offVec[0]) {
512 fin += s(last,offVec[0]-last);
518 ReplaceSubs(s, fin, replacePattern, offVec, nrMatch);
520 fin += replacePattern;
528 if (offVec[0] != offVec[1]) {
532 if (offVec[1] == s.
Length())
break;
538 pcre2_match_data_free(match_data);
542 fin += s(last,s.
Length()-last);
616 Int_t nrMatch =
r.Match(*
this,
"",start,10,&pos);
631 const Int_t nrMatch =
r.Match(*
this,
"",start,10,&pos);
633 *extent = pos[1]-pos[0];
656 return (*
this)(
r, 0);
681 fAddressOfLastString(nullptr),
682 fLastGlobalPosition(0)
696 fNMaxMatches(nMatchMax),
698 fAddressOfLastString(nullptr),
699 fLastGlobalPosition(0)
714 fNMaxMatches(nMatchMax),
716 fAddressOfLastString(nullptr),
717 fLastGlobalPosition(0)
730 fNMaxMatches(
r.fNMaxMatches),
732 fAddressOfLastString(nullptr),
733 fLastGlobalPosition(0)
856 typedef std::pair<int, int> MarkerLoc_t;
857 typedef std::vector<MarkerLoc_t> MarkerLocVec_t;
860 MarkerLocVec_t oMarks;
867 MarkerLocVec_t oCurrentTrailingEmpties;
870 Int_t nMatchesFound = 0;
876 while ((matchRes =
Match(s, nOffset)) &&
877 ((maxfields < 1) || nMatchesFound < maxfields)) {
881 oMarks.push_back(MarkerLoc_t(nOffset, nOffset + 1));
883 if (nOffset >= s.
Length())
891 if (!oCurrentTrailingEmpties.empty()) {
892 oMarks.insert(oMarks.end(),
893 oCurrentTrailingEmpties.begin(),
894 oCurrentTrailingEmpties.end());
895 oCurrentTrailingEmpties.clear();
897 oMarks.push_back(MarkerLoc_t(nOffset,
fMarkers[0]));
900 if (maxfields == 0) {
902 oCurrentTrailingEmpties.push_back(MarkerLoc_t(nOffset, nOffset));
904 oMarks.push_back(MarkerLoc_t(nOffset, nOffset));
911 for (
Int_t i = 1; i < matchRes; ++i)
918 if (nMatchesFound == 0) {
919 oMarks.push_back(MarkerLoc_t(0, s.
Length()));
923 else if (maxfields > 0 && nMatchesFound >= maxfields) {
924 oMarks[oMarks.size() - 1].second = s.
Length();
929 if (!last_empty || maxfields < 0) {
930 if (!oCurrentTrailingEmpties.empty()) {
931 oMarks.insert(oMarks.end(),
932 oCurrentTrailingEmpties.begin(),
933 oCurrentTrailingEmpties.end());
935 oMarks.push_back(MarkerLoc_t(nOffset, s.
Length()));
943 fMarkers[2*i + 1] = oMarks[i].second;
976 case 0 : ret +=
'\\';
break;
977 case 'l': state = 1;
break;
978 case 'u': state = 2;
break;
979 case 'L': state = 3;
break;
980 case 'U': state = 4;
break;
981 case 'E': state = 0;
break;
982 default : ret +=
'\\'; ret +=
c;
break;
987 case 0: ret +=
c;
break;
988 case 1: ret += (
Char_t) tolower(
c); state = 0;
break;
989 case 2: ret += (
Char_t) toupper(
c); state = 0;
break;
990 case 3: ret += (
Char_t) tolower(
c);
break;
991 case 4: ret += (
Char_t) toupper(
c);
break;
992 default:
Error(
"TPMERegexp::Substitute",
"invalid state.");
1032 Printf(
" %d - %s", i,
operator[](i).Data());
1057 fReturnVoid (retVoid),
void Info(const char *location, const char *msgfmt,...)
Use this function for informational messages.
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h offset
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t r
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t index
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t UChar_t len
void Printf(const char *fmt,...)
Formats a string in a circular formatting buffer and prints the string.
Array of integers (32 bits per element).
void Set(Int_t n) override
Set size of this array to n ints.
virtual void SetOwner(Bool_t enable=kTRUE)
Set whether this collection is the owner (enable==true) of its content.
void Add(TObject *obj) override
Collectable string class.
Wrapper for PCRE library (Perl Compatible Regular Expressions).
Int_t fLastGlobalPosition
void ResetGlobalState()
Reset state of global match.
void * fAddressOfLastString
virtual void Print(Option_t *option="")
Print the regular expression and modifier options.
Int_t Split(const TString &s, Int_t maxfields=0)
Splits into at most maxfields.
TPMERegexp()
Default constructor. This regexp will match an empty string.
Int_t Substitute(TString &s, const TString &r, Bool_t doDollarSubst=kTRUE)
Substitute matching part of s with r, dollar back-ref substitution is performed if doDollarSubst is t...
TString operator[](Int_t)
Returns the sub-string from the internal fMarkers vector.
Int_t Match(const TString &s, UInt_t start=0)
Runs a match on s against the regex 'this' was created with.
void Reset(const TString &s, const TString &opts="", Int_t nMatchMax=-1)
Reset the pattern and options.
TString fLastStringMatched
void AssignGlobalState(const TPMERegexp &re)
Copy global-match state from 're; so that this regexp can continue parsing the string from where 're'...
void Compile()
Compile the fPattern.
Int_t SubstituteInternal(TString &s, const TString &replace, Int_t start, Int_t nMaxMatch0, Bool_t doDollarSubst) const
Perform pattern substitution with optional back-ref replacement.
Bool_t IsValid() const
Returns true if underlying PCRE structure has been successfully generated via regexp compilation.
TPRegexp & operator=(const TPRegexp &p)
Assignment operator.
UInt_t ParseMods(const TString &mods) const
Translate Perl modifier flags into pcre flags.
Int_t Match(const TString &s, const TString &mods="", Int_t start=0, Int_t nMaxMatch=10, TArrayI *pos=nullptr)
The number of matches is returned, this equals the full match + sub-pattern matches.
TObjArray * MatchS(const TString &s, const TString &mods="", Int_t start=0, Int_t nMaxMatch=10)
Returns a TObjArray of matched substrings as TObjString's.
static Bool_t fgThrowAtCompileError
Int_t ReplaceSubs(const TString &s, TString &final, const TString &replacePattern, Int_t *ovec, Int_t nmatch) const
Returns the number of expanded '$' constructs.
virtual ~TPRegexp()
Cleanup.
Int_t Substitute(TString &s, const TString &replace, const TString &mods="", Int_t start=0, Int_t nMatchMax=10)
Substitute replaces the string s by a new string in which matching patterns are replaced by the repla...
Int_t MatchInternal(const TString &s, Int_t start, Int_t nMaxMatch, TArrayI *pos=nullptr) const
Perform the actual matching - protected method.
TString GetModifiers() const
Return PCRE modifier options as string.
static Bool_t GetThrowAtCompileError()
Get value of static flag controlling whether exception should be thrown upon an error during regular ...
void Optimize()
Send the pattern through the optimizer.
static void SetThrowAtCompileError(Bool_t throwp)
Set static flag controlling whether exception should be thrown upon an error during regular expressio...
Provides iteration through tokens of a given string.
TStringToken(const TString &fullStr, const TString &splitRe, Bool_t retVoid=kFALSE)
Constructor.
Bool_t NextToken()
Get the next token, it is stored in this TString.
char & operator()(Ssiz_t i)
void ToLower()
Change string to lower-case.
const char * Data() const
TString & operator=(char s)
Assign character c to TString.
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
A zero length substring is legal.