Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TPRegexp Class Reference

Definition at line 36 of file TPRegexp.h.

Public Member Functions

 TPRegexp ()
 Default ctor.
 
 TPRegexp (const TPRegexp &p)
 Copy ctor.
 
 TPRegexp (const TString &pat)
 Create and initialize with pat.
 
virtual ~TPRegexp ()
 Cleanup.
 
TString GetModifiers () const
 Return PCRE modifier options as string.
 
TString GetPattern () const
 
virtual TClassIsA () const
 
Bool_t IsValid () const
 Returns true if underlying PCRE structure has been successfully generated via regexp compilation.
 
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.
 
Bool_t MatchB (const TString &s, const TString &mods="", Int_t start=0, Int_t nMaxMatch=10)
 
TObjArrayMatchS (const TString &s, const TString &mods="", Int_t start=0, Int_t nMaxMatch=10)
 Returns a TObjArray of matched substrings as TObjString's.
 
TPRegexpoperator= (const TPRegexp &p)
 Assignment operator.
 
virtual void Streamer (TBuffer &)
 
void StreamerNVirtual (TBuffer &ClassDef_StreamerNVirtual_b)
 
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.
 

Static Public Member Functions

static TClassClass ()
 
static const char * Class_Name ()
 
static constexpr Version_t Class_Version ()
 
static const char * DeclFileName ()
 
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.
 
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.
 

Protected Types

enum  { kPCRE_GLOBAL = 0x80000000 , kPCRE_OPTIMIZE = 0x40000000 , kPCRE_DEBUG_MSGS = 0x20000000 , kPCRE_INTMASK = 0x0FFF }
 

Protected Member Functions

void Compile ()
 Compile the fPattern.
 
Int_t MatchInternal (const TString &s, Int_t start, Int_t nMaxMatch, TArrayI *pos=nullptr) const
 Perform the actual matching - protected method.
 
void Optimize ()
 Send the pattern through the optimizer.
 
UInt_t ParseMods (const TString &mods) const
 Translate Perl modifier flags into pcre flags.
 
Int_t ReplaceSubs (const TString &s, TString &final, const TString &replacePattern, Int_t *ovec, Int_t nmatch) const
 Returns the number of expanded '$' constructs.
 
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.
 

Protected Attributes

TString fPattern
 
UInt_t fPCREOpts
 
PCREPriv_tfPriv
 

Static Protected Attributes

static Bool_t fgThrowAtCompileError = kFALSE
 

#include <TPRegexp.h>

Inheritance diagram for TPRegexp:
[legend]

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
protected
Enumerator
kPCRE_GLOBAL 
kPCRE_OPTIMIZE 
kPCRE_DEBUG_MSGS 
kPCRE_INTMASK 

Definition at line 39 of file TPRegexp.h.

Constructor & Destructor Documentation

◆ TPRegexp() [1/3]

TPRegexp::TPRegexp ( )

Default ctor.

Definition at line 68 of file TPRegexp.cxx.

◆ TPRegexp() [2/3]

TPRegexp::TPRegexp ( const TString pat)

Create and initialize with pat.

Definition at line 77 of file TPRegexp.cxx.

◆ TPRegexp() [3/3]

TPRegexp::TPRegexp ( const TPRegexp p)

Copy ctor.

Definition at line 87 of file TPRegexp.cxx.

◆ ~TPRegexp()

TPRegexp::~TPRegexp ( )
virtual

Cleanup.

Definition at line 97 of file TPRegexp.cxx.

Member Function Documentation

◆ Class()

static TClass * TPRegexp::Class ( )
static
Returns
TClass describing this class

◆ Class_Name()

static const char * TPRegexp::Class_Name ( )
static
Returns
Name of this class

◆ Class_Version()

static constexpr Version_t TPRegexp::Class_Version ( )
inlinestaticconstexpr
Returns
Version of this class

Definition at line 93 of file TPRegexp.h.

◆ Compile()

void TPRegexp::Compile ( )
protected

Compile the fPattern.

Definition at line 226 of file TPRegexp.cxx.

◆ DeclFileName()

static const char * TPRegexp::DeclFileName ( )
inlinestatic
Returns
Name of the file containing the class declaration

Definition at line 93 of file TPRegexp.h.

◆ GetModifiers()

TString TPRegexp::GetModifiers ( ) const

Return PCRE modifier options as string.

For meaning of mods see ParseMods().

Definition at line 208 of file TPRegexp.cxx.

◆ GetPattern()

TString TPRegexp::GetPattern ( ) const
inline

Definition at line 85 of file TPRegexp.h.

◆ GetThrowAtCompileError()

Bool_t TPRegexp::GetThrowAtCompileError ( )
static

Get value of static flag controlling whether exception should be thrown upon an error during regular expression compilation by the PCRE engine.

Definition at line 588 of file TPRegexp.cxx.

◆ IsA()

virtual TClass * TPRegexp::IsA ( ) const
inlinevirtual
Returns
TClass describing current object

Reimplemented in TPMERegexp.

Definition at line 93 of file TPRegexp.h.

◆ IsValid()

Bool_t TPRegexp::IsValid ( ) const

Returns true if underlying PCRE structure has been successfully generated via regexp compilation.

Definition at line 579 of file TPRegexp.cxx.

◆ Match()

Int_t TPRegexp::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.

nMaxMatch is the maximum allowed number of matches. pos contains the string indices of the matches. Its usage is shown in the routine MatchS. For meaning of mods see ParseMods().

Definition at line 410 of file TPRegexp.cxx.

◆ MatchB()

Bool_t TPRegexp::MatchB ( const TString s,
const TString mods = "",
Int_t  start = 0,
Int_t  nMaxMatch = 10 
)
inline

Definition at line 78 of file TPRegexp.h.

◆ MatchInternal()

Int_t TPRegexp::MatchInternal ( const TString s,
Int_t  start,
Int_t  nMaxMatch,
TArrayI pos = nullptr 
) const
protected

Perform the actual matching - protected method.

Definition at line 356 of file TPRegexp.cxx.

◆ MatchS()

TObjArray * TPRegexp::MatchS ( const TString s,
const TString mods = "",
Int_t  start = 0,
Int_t  nMaxMatch = 10 
)

Returns a TObjArray of matched substrings as TObjString's.

The TObjArray is owner of the objects and must be deleted by the user. The first entry is the full matched pattern, followed by the sub-patterns. If a pattern was not matched, it will return an empty substring:

TObjArray *subStrL = TPRegexp("(a|(z))(bc)").MatchS("abc");
for (Int_t i = 0; i < subStrL->GetLast()+1; i++) {
const TString subStr = ((TObjString *)subStrL->At(i))->GetString();
std::cout << "\"" << subStr << "\" ";
}
std::cout << subStr << std::endl;
An array of TObjects.
Definition TObjArray.h:31
TObject * At(Int_t idx) const override
Definition TObjArray.h:164
Int_t GetLast() const override
Return index of last object in array.
Collectable string class.
Definition TObjString.h:28
TPRegexp()
Default ctor.
Definition TPRegexp.cxx:68
Basic string class.
Definition TString.h:139

produces: "abc" "a" "" "bc"

For meaning of mods see ParseMods().

Definition at line 441 of file TPRegexp.cxx.

◆ operator=()

TPRegexp & TPRegexp::operator= ( const TPRegexp p)

Assignment operator.

Definition at line 114 of file TPRegexp.cxx.

◆ Optimize()

void TPRegexp::Optimize ( )
protected

Send the pattern through the optimizer.

Definition at line 277 of file TPRegexp.cxx.

◆ ParseMods()

UInt_t TPRegexp::ParseMods ( const TString modStr) const
protected

Translate Perl modifier flags into pcre flags.

The supported modStr characters are: g, i, m, o, s, x, and the special d for debug. The meaning of the letters is:

  • m Treat string as multiple lines. That is, change "^" and "$" from matching the start or end of the string to matching the start or end of any line anywhere within the string.
  • s Treat string as single line. That is, change "." to match any character whatsoever, even a newline, which normally it would not match. Used together, as /ms, they let the "." match any character whatsoever, while still allowing "^" and "$" to match, respectively, just after and just before newlines within the string.
  • i Do case-insensitive pattern matching.
  • x Extend your pattern's legibility by permitting whitespace and comments.
  • p Preserve the string matched such that ${^PREMATCH}, ${^MATCH}, and ${^POSTMATCH} are available for use after matching.
  • g and c Global matching, and keep the Current position after failed matching. Unlike i, m, s and x, these two flags affect the way the regex is used rather than the regex itself. See Using regular expressions in Perl in perlretut for further explanation of the g and c modifiers. For more detail see: http://perldoc.perl.org/perlre.html#Modifiers.

Definition at line 163 of file TPRegexp.cxx.

◆ ReplaceSubs()

Int_t TPRegexp::ReplaceSubs ( const TString s,
TString final,
const TString replacePattern,
Int_t ovec,
Int_t  nmatch 
) const
protected

Returns the number of expanded '$' constructs.

Definition at line 300 of file TPRegexp.cxx.

◆ SetThrowAtCompileError()

void TPRegexp::SetThrowAtCompileError ( Bool_t  throwp)
static

Set static flag controlling whether exception should be thrown upon an error during regular expression compilation by the PCRE engine.

Definition at line 597 of file TPRegexp.cxx.

◆ Streamer()

virtual void TPRegexp::Streamer ( TBuffer )
virtual

Reimplemented in TPMERegexp.

◆ StreamerNVirtual()

void TPRegexp::StreamerNVirtual ( TBuffer ClassDef_StreamerNVirtual_b)
inline

Definition at line 93 of file TPRegexp.h.

◆ Substitute()

Int_t TPRegexp::Substitute ( TString s,
const TString replacePattern,
const TString mods = "",
Int_t  start = 0,
Int_t  nMaxMatch = 10 
)

Substitute replaces the string s by a new string in which matching patterns are replaced by the replacePattern string.

The number of substitutions are returned.

TString s("aap noot mies");
const Int_t nrSub = TPRegexp("(\\w*) noot (\\w*)").Substitute(s,"$2 noot $1");
std::cout << nrSub << " \"" << s << "\"" <<std::endl;

produces: 2 "mies noot aap"

For meaning of mods see ParseMods().

Definition at line 561 of file TPRegexp.cxx.

◆ SubstituteInternal()

Int_t TPRegexp::SubstituteInternal ( TString s,
const TString replacePattern,
Int_t  start,
Int_t  nMaxMatch,
Bool_t  doDollarSubst 
) const
protected

Perform pattern substitution with optional back-ref replacement.

  • protected method.

Definition at line 467 of file TPRegexp.cxx.

Member Data Documentation

◆ fgThrowAtCompileError

Bool_t TPRegexp::fgThrowAtCompileError = kFALSE
staticprotected

Definition at line 50 of file TPRegexp.h.

◆ fPattern

TString TPRegexp::fPattern
protected

Definition at line 46 of file TPRegexp.h.

◆ fPCREOpts

UInt_t TPRegexp::fPCREOpts
protected

Definition at line 48 of file TPRegexp.h.

◆ fPriv

PCREPriv_t* TPRegexp::fPriv
protected

Definition at line 47 of file TPRegexp.h.

Libraries for TPRegexp:

The documentation for this class was generated from the following files: