ROOT
6.07/01
Reference Guide
|
Wrapper for PCRE library (Perl Compatible Regular Expressions).
Based on PME - PCRE Made Easy by Zachary Hansen.
Supports main Perl operations using regular expressions (Match, Substitute and Split). To retrieve the results one can simply use operator[] returning a TString.
See $ROOTSYS/tutorials/regexp_pme.C for examples.
Definition at line 103 of file TPRegexp.h.
Public Member Functions | |
TPMERegexp () | |
Default constructor. This regexp will match an empty string. More... | |
TPMERegexp (const TString &s, const TString &opts="", Int_t nMatchMax=10) | |
Constructor. More... | |
TPMERegexp (const TString &s, UInt_t opts, Int_t nMatchMax=10) | |
Constructor. More... | |
TPMERegexp (const TPMERegexp &r) | |
Copy constructor. More... | |
virtual | ~TPMERegexp () |
void | Reset (const TString &s, const TString &opts="", Int_t nMatchMax=-1) |
Reset the pattern and options. More... | |
void | Reset (const TString &s, UInt_t opts, Int_t nMatchMax=-1) |
Reset the pattern and options. More... | |
Int_t | GetNMaxMatches () const |
void | SetNMaxMatches (Int_t nm) |
Int_t | GetGlobalPosition () const |
void | AssignGlobalState (const TPMERegexp &re) |
Copy global-match state from 're; so that this regexp can continue parsing the string from where 're' left off. More... | |
void | ResetGlobalState () |
Reset state of global match. More... | |
Int_t | Match (const TString &s, UInt_t start=0) |
Runs a match on s against the regex 'this' was created with. More... | |
Int_t | Split (const TString &s, Int_t maxfields=0) |
Splits into at most maxfields. More... | |
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 true (default). More... | |
Int_t | NMatches () const |
TString | operator[] (Int_t) |
Returns the sub-string from the internal fMarkers vector. More... | |
virtual void | Print (Option_t *option="") |
Print the regular expression and modifier options. More... | |
ClassDef (TPMERegexp, 0) | |
Protected Attributes | |
Int_t | fNMaxMatches |
Int_t | fNMatches |
TArrayI | fMarkers |
TString | fLastStringMatched |
void * | fAddressOfLastString |
Int_t | fLastGlobalPosition |
Protected Attributes inherited from TPRegexp | |
TString | fPattern |
PCREPriv_t * | fPriv |
UInt_t | fPCREOpts |
Private Member Functions | |
TPMERegexp & | operator= (const TPMERegexp &) |
Additional Inherited Members | |
Protected Types inherited from TPRegexp | |
enum | { kPCRE_GLOBAL = 0x80000000, kPCRE_OPTIMIZE = 0x40000000, kPCRE_DEBUG_MSGS = 0x20000000, kPCRE_INTMASK = 0x0FFF } |
Protected Member Functions inherited from TPRegexp | |
void | Compile () |
Compile the fPattern. More... | |
void | Optimize () |
Send the pattern through the optimizer. More... | |
UInt_t | ParseMods (const TString &mods) const |
Translate Perl modifier flags into pcre flags. More... | |
Int_t | ReplaceSubs (const TString &s, TString &final, const TString &replacePattern, Int_t *ovec, Int_t nmatch) const |
Returns the number of expanded '$' constructs. More... | |
Int_t | MatchInternal (const TString &s, Int_t start, Int_t nMaxMatch, TArrayI *pos=0) const |
Perform the actual matching - protected method. More... | |
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. More... | |
TPRegexp () | |
TPRegexp (const TString &pat) | |
Create and initialize with pat. More... | |
TPRegexp (const TPRegexp &p) | |
Copy ctor. More... | |
virtual | ~TPRegexp () |
Cleanup. More... | |
Bool_t | IsValid () const |
Returns true if underlying PCRE structure has been successfully generated via regexp compilation. More... | |
Int_t | Match (const TString &s, const TString &mods="", Int_t start=0, Int_t nMaxMatch=10, TArrayI *pos=0) |
The number of matches is returned, this equals the full match + sub-pattern matches. More... | |
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. More... | |
Bool_t | MatchB (const TString &s, const TString &mods="", Int_t start=0, Int_t nMaxMatch=10) |
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 replacePattern string. More... | |
TString | GetPattern () const |
TString | GetModifiers () const |
Return PCRE modifier options as string. More... | |
TPRegexp & | operator= (const TPRegexp &p) |
Assignment operator. More... | |
Static Protected Member Functions inherited from TPRegexp | |
static Bool_t | GetThrowAtCompileError () |
Get value of static flag controlling whether exception should be thrown upon an error during regular expression compilation by the PCRE engine. More... | |
static void | SetThrowAtCompileError (Bool_t throwp) |
Set static flag controlling whether exception should be thrown upon an error during regular expression compilation by the PCRE engine. More... | |
Static Protected Attributes inherited from TPRegexp | |
static Bool_t | fgThrowAtCompileError |
#include <TPRegexp.h>
TPMERegexp::TPMERegexp | ( | ) |
Default constructor. This regexp will match an empty string.
Definition at line 584 of file TPRegexp.cxx.
Constructor.
[in] | s | string to compile into regular expression |
[in] | opts | perl-style character flags to be set on TPME object |
[in] | nMatchMax | maximum number of matches |
Definition at line 601 of file TPRegexp.cxx.
Constructor.
[in] | s | string to compile into regular expression |
[in] | opts | PCRE-style option flags to be set on TPME object |
[in] | nMatchMax | maximum number of matches |
Definition at line 619 of file TPRegexp.cxx.
TPMERegexp::TPMERegexp | ( | const TPMERegexp & | r | ) |
Copy constructor.
Only PCRE specifics are copied, not last-match or global-match information.
Definition at line 635 of file TPRegexp.cxx.
|
inlinevirtual |
Definition at line 124 of file TPRegexp.h.
void TPMERegexp::AssignGlobalState | ( | const TPMERegexp & | re | ) |
Copy global-match state from 're; so that this regexp can continue parsing the string from where 're' left off.
Alternatively, GetGlobalPosition() get be used to retrieve the last match position so that it can passed to Match().
Ideally, as it is done in PERL, the last match position would be stored in the TString itself.
Definition at line 680 of file TPRegexp.cxx.
TPMERegexp::ClassDef | ( | TPMERegexp | , |
0 | |||
) |
|
inline |
Definition at line 132 of file TPRegexp.h.
|
inline |
Definition at line 129 of file TPRegexp.h.
Runs a match on s against the regex 'this' was created with.
[in] | s | string to match against |
[in] | start | offset at which to start matching |
Definition at line 704 of file TPRegexp.cxx.
Referenced by ClassImp(), TDocOutput::Convert(), THtml::CreateListOfClasses(), TDataSetManagerAliEn::ExpandRunSpec(), TDataSetManagerAliEn::GetFindCommandsFromUri(), TAliEnFind::GetGridResult(), TFile::GetType(), TProofLite::InitDataSetManager(), TDocParser::LocateMethods(), TDataSetManagerAliEn::ParseCustomFindUri(), TDataSetManagerAliEn::ParseOfficialDataUri(), TS3WebFile::ParseOptions(), TDataSetManager::ParseUri(), TFileCollection::Print(), TS3WebFile::ProcessHttpHeader(), regexp_pme(), TEveManager::SaveVizDB(), TProof::SaveWorkerInfo(), TProofServ::SetupCommon(), Split(), TDataSetManagerAliEn::TDataSetManagerAliEn(), and TEveMacro::TEveMacro().
|
inline |
Definition at line 140 of file TPRegexp.h.
|
private |
Returns the sub-string from the internal fMarkers vector.
Requires having run match or split first.
Definition at line 914 of file TPRegexp.cxx.
Print the regular expression and modifier options.
If 'option' contains "all", prints also last string match and match results.
Definition at line 929 of file TPRegexp.cxx.
Referenced by regexp_pme().
Reset the pattern and options.
If 'nMatchMax' other than -1 (the default) is passed, it is also set.
Definition at line 649 of file TPRegexp.cxx.
Reset the pattern and options.
If 'nMatchMax' other than -1 (the default) is passed, it is also set.
Definition at line 658 of file TPRegexp.cxx.
void TPMERegexp::ResetGlobalState | ( | ) |
Reset state of global match.
This happens automatically when a new string is passed for matching. But be carefull, as the address of last TString object is used to make this decision.
Definition at line 692 of file TPRegexp.cxx.
Definition at line 130 of file TPRegexp.h.
Splits into at most maxfields.
If maxfields is unspecified or 0, trailing empty matches are discarded. If maxfields is positive, no more than maxfields fields will be returned and trailing empty matches are preserved. If maxfields is empty, all fields (including trailing empty ones) are returned. This should be the same as the perl behaviour.
If pattern produces sub-matches, these are also stored in the result.
A pattern matching the null string will split the value of EXPR into separate characters at each point it matches that way.
[in] | s | string to split |
[in] | maxfields | maximum number of fields to be split out. 0 means split all fields, but discard any trailing empty bits. Negative means split all fields and keep trailing empty bits. Positive means keep up to N fields including any empty fields less than N. Anything remaining is in the last field. |
Definition at line 761 of file TPRegexp.cxx.
Referenced by regexp_pme().
Substitute matching part of s with r, dollar back-ref substitution is performed if doDollarSubst is true (default).
Returns the number of substitutions made.
After the substitution, another pass is made over the resulting string and the following special tokens are interpreted:
\l
lowercase next char,\u
uppercase next char,\L
lowercase till \E
,\U
uppercase till \E
, and\E
end case modification. Definition at line 870 of file TPRegexp.cxx.
Referenced by TProofLite::CancelStagingDataSet(), ClassImpQ(), TProofProgressLog::DoLog(), TGLAxisPainter::FormAxisValue(), TDataSetManagerAliEn::GetDataSet(), TAliEnFind::GetGridResult(), TProofLite::GetStagingStatusDataSet(), TProofServ::HandleDataSets(), regexp_pme(), TProofLite::RequestStagingDataSet(), and TEveManager::TEveManager().
|
protected |
Definition at line 114 of file TPRegexp.h.
Referenced by Match().
|
protected |
Definition at line 116 of file TPRegexp.h.
Referenced by AssignGlobalState(), GetGlobalPosition(), Match(), Reset(), and ResetGlobalState().
|
protected |
Definition at line 113 of file TPRegexp.h.
Referenced by AssignGlobalState(), Match(), operator[](), and Print().
|
protected |
Definition at line 111 of file TPRegexp.h.
Referenced by Match(), operator[](), and Split().
|
protected |
Definition at line 110 of file TPRegexp.h.
Referenced by Match(), NMatches(), operator[](), Print(), Reset(), and Split().
|
protected |
Definition at line 109 of file TPRegexp.h.
Referenced by GetNMaxMatches(), Match(), SetNMaxMatches(), and Substitute().