Skip to content

Commit

Permalink
Several new Core features:
Browse files Browse the repository at this point in the history
- new TPRegexp class by Eddy Offermann using the PCRE library for powerful
  regexp matching. TPRegexp is fully integrated in TString and can be
  used like TRegExp. For more see the TPRegexp clas description.
- Extended TString::Atoi(), Atof(), IsDigit() and new IsFloat() by
  John Frankland. For more see the method description.


git-svn-id: http://root.cern.ch/svn/root/trunk@13456 27541ba8-7e3a-0410-8455-c3a389f83636
  • Loading branch information
FonsRademakers committed Dec 2, 2005
1 parent 86f5f6d commit 0205b69
Show file tree
Hide file tree
Showing 10 changed files with 758 additions and 27 deletions.
12 changes: 6 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ endif

##### Modules to build #####

MODULES = build cint metautils utils base cont meta net auth zip clib \
matrix newdelete hist tree freetype graf g3d gpad gui minuit \
histpainter treeplayer treeviewer physics postscript \
MODULES = build cint metautils pcre utils base cont meta net auth zip \
clib matrix newdelete hist tree freetype graf g3d gpad gui \
minuit histpainter treeplayer treeviewer physics postscript \
rint html eg geom geompainter vmc fumili mlp gedold ged quadp \
guibuilder xml foam splot smatrix

Expand Down Expand Up @@ -441,15 +441,15 @@ G__%.d: G__%.cxx $(RMKDEP)
%.d: %.cxx $(RMKDEP)
$(MAKEDEP) $@ "$(CXXFLAGS)" $< > $@

$(CORELIB): $(COREO) $(COREDO) $(CINTLIB) $(CORELIBDEP)
$(CORELIB): $(COREO) $(COREDO) $(CINTLIB) $(PCREDEP) $(CORELIBDEP)
ifneq ($(ARCH),alphacxx6)
@$(MAKELIB) $(PLATFORM) $(LD) "$(LDFLAGS)" \
"$(SOFLAGS)" libCore.$(SOEXT) $@ "$(COREO) $(COREDO)" \
"$(CORELIBEXTRA) $(CRYPTLIBS)"
"$(CORELIBEXTRA) $(PCRELDFLAGS) $(PCRELIB) $(CRYPTLIBS)"
else
@$(MAKELIB) $(PLATFORM) $(LD) "$(CORELDFLAGS)" \
"$(SOFLAGS)" libCore.$(SOEXT) $@ "$(COREO) $(COREDO)" \
"$(CORELIBEXTRA) $(CRYPTLIBS)"
"$(CORELIBEXTRA) $(PCRELDFLAGS) $(PCRELIB) $(CRYPTLIBS)"
endif

map:: $(RLIBMAP)
Expand Down
11 changes: 7 additions & 4 deletions base/Module.mk
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ $(BASEDS4):
@echo "Generating dictionary $@..."
$(ROOTCINTTMP) -f $@ -c $(BASEH4) $(BASEL4)

$(BASEDO1): $(BASEDS1)
$(CXX) $(NOOPT) $(CXXFLAGS) -I. -o $@ -c $<
$(BASEDO2): $(BASEDS2)
$(CXX) $(NOOPT) $(CXXFLAGS) -I. -o $@ -c $<
$(BASEDO1): $(BASEDS1) $(PCREDEP)
$(CXX) $(NOOPT) $(PCREINC) $(CXXFLAGS) -I. -o $@ -c $<
$(BASEDO2): $(BASEDS2) $(PCREDEP)
$(CXX) $(NOOPT) $(PCREINC) $(CXXFLAGS) -I. -o $@ -c $<
ifeq ($(ARCH),linuxicc)
$(BASEDO3): $(BASEDS3)
$(CXX) $(NOOPT) $(CXXFLAGS) -wd191 -I. -o $@ -c $<
Expand All @@ -108,6 +108,9 @@ distclean-base: clean-base
distclean:: distclean-base

##### extra rules ######
base/src/TPRegexp.o: base/src/TPRegexp.cxx $(PCREDEP)
$(CXX) $(OPT) $(PCREINC) $(CXXFLAGS) -o $@ -c $<

ifeq ($(ARCH),alphacxx6)
$(BASEDIRS)/TRandom.o: $(BASEDIRS)/TRandom.cxx
$(CXX) $(NOOPT) $(CXXFLAGS) -o $@ -c $<
Expand Down
3 changes: 2 additions & 1 deletion base/inc/LinkDef2.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* @(#)root/base:$Name: $:$Id: LinkDef2.h,v 1.29 2004/11/03 11:05:12 rdm Exp $ */
/* @(#)root/base:$Name: $:$Id: LinkDef2.h,v 1.30 2005/08/16 12:57:57 brun Exp $ */

/*************************************************************************
* Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
Expand Down Expand Up @@ -102,6 +102,7 @@
#pragma link C++ class TROOT;
#pragma link C++ class TRealData+;
#pragma link C++ class TRegexp;
#pragma link C++ class TPRegexp;
#pragma link C++ class TRefCnt;
#pragma link C++ class TSignalHandler;
#pragma link C++ class TStopwatch+;
Expand Down
85 changes: 85 additions & 0 deletions base/inc/TPRegexp.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
// @(#)root/base:$Name: $:$Id: TRegexp.h,v 1.1.1.1 2000/05/16 17:00:39 rdm Exp $
// Author: Eddy Offermann 24/06/05

/*************************************************************************
* Copyright (C) 1995-2005, Rene Brun and Fons Rademakers. *
* All rights reserved. *
* *
* For the licensing terms see $ROOTSYS/LICENSE. *
* For the list of contributors see $ROOTSYS/README/CREDITS. *
*************************************************************************/

#ifndef ROOT_TPRegexp
#define ROOT_TPRegexp

//////////////////////////////////////////////////////////////////////////
// //
// TPRegexp //
// //
// C++ Wrapper for the "Perl Compatible Regular Expressions" library //
// The PCRE lib can be found at: //
// http://www.pcre.org/ //
// //
// Extensive documentation about Regular expressions in Perl can be //
// found at : //
// http://perldoc.perl.org/perlre.html //
// //
//////////////////////////////////////////////////////////////////////////

#ifndef ROOT_Rtypes
#include "Rtypes.h"
#endif
#ifndef ROOT_TString
#include "TString.h"
#endif
#ifndef ROOT_TArrayI
#include "TArrayI.h"
#endif

struct PCREPriv_t;


class TPRegexp {

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

TString fPattern;
PCREPriv_t *fPriv;
UInt_t fPCREOpts;

void Compile();
void Optimize();
UInt_t ParseMods(const TString &mods) const;
Int_t ReplaceSubs(const TString &s, TString &final,
const TString &replacePattern,
Int_t *ovec, Int_t nmatch) const;

public:
TPRegexp();
TPRegexp(const TString &pat);
TPRegexp(const TPRegexp &p);
virtual ~TPRegexp();

Int_t Match(const TString &s, const TString &mods="",
Int_t offset=0, Int_t nMatchMax=30, TArrayI *pos=0);
TObjArray *MatchS(const TString &s, const TString &mods="",
Int_t offset=0, Int_t nMaxMatch=30);
Bool_t MatchB(const TString &s, const TString &mods="",
Int_t offset=0, Int_t nMaxMatch=30) {
return (Match(s,mods,offset,nMaxMatch) > 0); }
Int_t Substitute(TString &s, const TString &replace,
const TString &mods="", Int_t offset=0,
Int_t nMatchMax=30);

TPRegexp &operator=(const TPRegexp &p);

ClassDef(TPRegexp,0) // Perl Compatible Regular Expression Class
};

#endif
20 changes: 13 additions & 7 deletions base/inc/TString.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// @(#)root/base:$Name: $:$Id: TString.h,v 1.40 2005/08/15 21:21:46 pcanal Exp $
// @(#)root/base:$Name: $:$Id: TString.h,v 1.41 2005/11/21 11:17:18 rdm Exp $
// Author: Fons Rademakers 04/08/95

/*************************************************************************
Expand Down Expand Up @@ -47,6 +47,7 @@ namespace std { using ::string; }
#endif

class TRegexp;
class TPRegexp;
class TString;
class TSubString;
class TObjArray;
Expand Down Expand Up @@ -272,13 +273,17 @@ friend Bool_t operator==(const TString &s1, const char *s2);
TSubString operator()(Ssiz_t start, Ssiz_t len); // Sub-string operator
TSubString operator()(const TRegexp &re); // Match the RE
TSubString operator()(const TRegexp &re, Ssiz_t start);
TSubString operator()(TPRegexp &re); // Match the Perl compatible Regular Expression
TSubString operator()(TPRegexp &re, Ssiz_t start);
TSubString SubString(const char *pat, Ssiz_t start = 0,
ECaseCompare cmp = kExact);
char operator[](Ssiz_t i) const;
char operator()(Ssiz_t i) const;
TSubString operator()(Ssiz_t start, Ssiz_t len) const;
TSubString operator()(const TRegexp &re) const; // Match the RE
TSubString operator()(const TRegexp &re, Ssiz_t start) const;
TSubString operator()(TPRegexp &re) const; // Match the Perl compatible Regular Expression
TSubString operator()(TPRegexp &re, Ssiz_t start) const;
TSubString SubString(const char *pat, Ssiz_t start = 0,
ECaseCompare cmp = kExact) const;

Expand All @@ -300,6 +305,7 @@ friend Bool_t operator==(const TString &s1, const char *s2);
Bool_t Contains(const char *pat, ECaseCompare cmp = kExact) const;
Bool_t Contains(const TString &pat, ECaseCompare cmp = kExact) const;
Bool_t Contains(const TRegexp &pat) const;
Bool_t Contains(TPRegexp &pat) const;
Int_t CountChar(Int_t c) const;
TString Copy() const;
const char *Data() const { return fData; }
Expand All @@ -318,6 +324,8 @@ friend Bool_t operator==(const TString &s1, const char *s2);
ECaseCompare cmp) const;
Ssiz_t Index(const TRegexp &pat, Ssiz_t i = 0) const;
Ssiz_t Index(const TRegexp &pat, Ssiz_t *ext, Ssiz_t i = 0) const;
Ssiz_t Index(TPRegexp &pat, Ssiz_t i = 0) const;
Ssiz_t Index(TPRegexp &pat, Ssiz_t *ext, Ssiz_t i = 0) const;
TString &Insert(Ssiz_t pos, const char *s);
TString &Insert(Ssiz_t pos, const char *s, Ssiz_t extent);
TString &Insert(Ssiz_t pos, const TString &s);
Expand All @@ -326,6 +334,7 @@ friend Bool_t operator==(const TString &s1, const char *s2);
Bool_t IsAlpha() const;
Bool_t IsAlnum() const;
Bool_t IsDigit() const;
Bool_t IsFloat() const;
Bool_t IsHex() const;
Bool_t IsNull() const { return Pref()->fNchars == 0; }
Ssiz_t Last(char c) const { return Pref()->Last(c); }
Expand Down Expand Up @@ -415,12 +424,6 @@ extern int strncasecmp(const char *str1, const char *str2, Ssiz_t n);
inline void TStringRef::UnLink()
{ if (RemoveReference() == 0) delete [] (char*)this; }

inline Int_t TString::Atoi() const
{ return atoi(fData); }

inline Double_t TString::Atof() const
{ return atof(fData); }

inline void TString::Cow()
{ if (Pref()->References() > 1) Clone(); }

Expand Down Expand Up @@ -493,6 +496,9 @@ inline Bool_t TString::Contains(const char *s, ECaseCompare cmp) const
inline Bool_t TString::Contains(const TRegexp &pat) const
{ return Index(pat, (Ssiz_t)0) != kNPOS; }

inline Bool_t TString::Contains(TPRegexp &pat) const
{ return Index(pat, (Ssiz_t)0) != kNPOS; }

inline Ssiz_t TString::Index(const char *s, Ssiz_t i, ECaseCompare cmp) const
{ return Index(s, s ? strlen(s) : 0, i, cmp); }

Expand Down
Loading

0 comments on commit 0205b69

Please sign in to comment.