#ifndef ROOT_TString
#define ROOT_TString
#ifndef __CINT__
#include <string.h>
#include <stdio.h>
#endif
#ifndef ROOT_TRefCnt
#include "TRefCnt.h"
#endif
#ifndef ROOT_Riosfwd
#include "Riosfwd.h"
#endif
#ifndef ROOT_TMathBase
#include "TMathBase.h"
#endif
#include <stdarg.h>
#include <string>
#ifdef R__GLOBALSTL
namespace std { using ::string; }
#endif
class TRegexp;
class TPRegexp;
class TString;
class TSubString;
class TObjArray;
class TVirtualMutex;
R__EXTERN TVirtualMutex *gStringMutex;
TString operator+(const TString &s1, const TString &s2);
TString operator+(const TString &s, const char *cs);
TString operator+(const char *cs, const TString &s);
TString operator+(const TString &s, char c);
TString operator+(const TString &s, Long_t i);
TString operator+(const TString &s, ULong_t i);
TString operator+(const TString &s, Long64_t i);
TString operator+(const TString &s, ULong64_t i);
TString operator+(char c, const TString &s);
TString operator+(Long_t i, const TString &s);
TString operator+(ULong_t i, const TString &s);
TString operator+(Long64_t i, const TString &s);
TString operator+(ULong64_t i, const TString &s);
Bool_t operator==(const TString &s1, const TString &s2);
Bool_t operator==(const TString &s1, const char *s2);
Bool_t operator==(const TSubString &s1, const TSubString &s2);
Bool_t operator==(const TSubString &s1, const TString &s2);
Bool_t operator==(const TSubString &s1, const char *s2);
class TStringRef : public TRefCnt {
friend class TString;
friend class TStringLong;
friend class TSubString;
private:
Ssiz_t fCapacity;
Ssiz_t fNchars;
void UnLink();
Ssiz_t Length() const { return fNchars; }
Ssiz_t Capacity() const { return fCapacity; }
char *Data() const { return (char*)(this+1); }
char &operator[](Ssiz_t i) { return ((char*)(this+1))[i]; }
char operator[](Ssiz_t i) const { return ((char*)(this+1))[i]; }
Ssiz_t First(char c) const;
Ssiz_t First(const char *s) const;
UInt_t Hash() const;
UInt_t HashFoldCase() const;
Ssiz_t Last(char) const;
static TStringRef *GetRep(Ssiz_t capac, Ssiz_t nchar);
};
class TSubString {
friend class TStringLong;
friend class TString;
friend Bool_t operator==(const TSubString &s1, const TSubString &s2);
friend Bool_t operator==(const TSubString &s1, const TString &s2);
friend Bool_t operator==(const TSubString &s1, const char *s2);
private:
TString &fStr;
Ssiz_t fBegin;
Ssiz_t fExtent;
TSubString(const TString &s, Ssiz_t start, Ssiz_t len);
protected:
void SubStringError(Ssiz_t, Ssiz_t, Ssiz_t) const;
void AssertElement(Ssiz_t i) const;
public:
TSubString(const TSubString &s)
: fStr(s.fStr), fBegin(s.fBegin), fExtent(s.fExtent) { }
TSubString &operator=(const char *s);
TSubString &operator=(const TString &s);
TSubString &operator=(const TSubString &s);
char &operator()(Ssiz_t i);
char &operator[](Ssiz_t i);
char operator()(Ssiz_t i) const;
char operator[](Ssiz_t i) const;
const char *Data() const;
Ssiz_t Length() const { return fExtent; }
Ssiz_t Start() const { return fBegin; }
TString& String() { return fStr; }
void ToLower();
void ToUpper();
Bool_t IsNull() const { return fBegin == kNPOS; }
int operator!() const { return fBegin == kNPOS; }
};
class TString {
friend class TSubString;
friend class TStringRef;
friend TString operator+(const TString &s1, const TString &s2);
friend TString operator+(const TString &s, const char *cs);
friend TString operator+(const char *cs, const TString &s);
friend TString operator+(const TString &s, char c);
friend TString operator+(const TString &s, Long_t i);
friend TString operator+(const TString &s, ULong_t i);
friend TString operator+(const TString &s, Long64_t i);
friend TString operator+(const TString &s, ULong64_t i);
friend TString operator+(char c, const TString &s);
friend TString operator+(Long_t i, const TString &s);
friend TString operator+(ULong_t i, const TString &s);
friend TString operator+(Long64_t i, const TString &s);
friend TString operator+(ULong64_t i, const TString &s);
friend Bool_t operator==(const TString &s1, const TString &s2);
friend Bool_t operator==(const TString &s1, const char *s2);
private:
static Ssiz_t fgInitialCapac;
static Ssiz_t fgResizeInc;
static Ssiz_t fgFreeboard;
void Clone();
void Clone(Ssiz_t nc);
void FormImp(const char *fmt, va_list ap);
protected:
char *fData;
TString(const char *a1, Ssiz_t n1, const char *a2, Ssiz_t n2);
TStringRef *Pref() const { return (((TStringRef*) fData) - 1); }
void AssertElement(Ssiz_t nc) const;
void Clobber(Ssiz_t nc);
void Cow();
void Cow(Ssiz_t nc);
static Ssiz_t AdjustCapacity(Ssiz_t nc);
void InitChar(char c);
public:
enum EStripType { kLeading = 0x1, kTrailing = 0x2, kBoth = 0x3 };
enum ECaseCompare { kExact, kIgnoreCase };
TString();
explicit TString(Ssiz_t ic);
TString(const TString &s) :
fData(s.fData) { Pref()->AddReference(); }
TString(const char *s);
TString(const char *s, Ssiz_t n);
TString(const std::string &s);
TString(char c) : fData(0) { InitChar(c); }
TString(char c, Ssiz_t s);
TString(const TSubString &sub);
virtual ~TString();
virtual void FillBuffer(char *&buffer);
virtual void ReadBuffer(char *&buffer);
virtual Int_t Sizeof() const;
static TString *ReadString(TBuffer &b, const TClass *clReq);
static void WriteString(TBuffer &b, const TString *a);
friend TBuffer &operator<<(TBuffer &b, const TString *obj);
Bool_t Gets(FILE *fp, Bool_t chop=kTRUE);
void Puts(FILE *fp);
operator const char*() const { return fData; }
TString &operator=(char s);
TString &operator=(const char *s);
TString &operator=(const TString &s);
TString &operator=(const std::string &s);
TString &operator=(const TSubString &s);
TString &operator+=(const char *s);
TString &operator+=(const TString &s);
TString &operator+=(char c);
TString &operator+=(Short_t i);
TString &operator+=(UShort_t i);
TString &operator+=(Int_t i);
TString &operator+=(UInt_t i);
TString &operator+=(Long_t i);
TString &operator+=(ULong_t i);
TString &operator+=(Float_t f);
TString &operator+=(Double_t f);
TString &operator+=(Long64_t i);
TString &operator+=(ULong64_t i);
char &operator[](Ssiz_t i);
char &operator()(Ssiz_t i);
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;
TSubString operator()(const TRegexp &re, Ssiz_t start) const;
TSubString operator()(TPRegexp &re) const;
TSubString operator()(TPRegexp &re, Ssiz_t start) const;
TSubString SubString(const char *pat, Ssiz_t start = 0,
ECaseCompare cmp = kExact) const;
TString &Append(const char *cs);
TString &Append(const char *cs, Ssiz_t n);
TString &Append(const TString &s);
TString &Append(const TString &s, Ssiz_t n);
TString &Append(char c, Ssiz_t rep = 1);
Int_t Atoi() const;
Long64_t Atoll() const;
Double_t Atof() const;
Bool_t BeginsWith(const char *s, ECaseCompare cmp = kExact) const;
Bool_t BeginsWith(const TString &pat, ECaseCompare cmp = kExact) const;
Ssiz_t Capacity() const { return Pref()->Capacity(); }
Ssiz_t Capacity(Ssiz_t n);
TString &Chop();
void Clear();
int CompareTo(const char *cs, ECaseCompare cmp = kExact) const;
int CompareTo(const TString &st, ECaseCompare cmp = kExact) const;
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; }
Bool_t EndsWith(const char *pat, ECaseCompare cmp = kExact) const;
Ssiz_t First(char c) const { return Pref()->First(c); }
Ssiz_t First(const char *cs) const { return Pref()->First(cs); }
void Form(const char *fmt, ...);
UInt_t Hash(ECaseCompare cmp = kExact) const;
Ssiz_t Index(const char *pat, Ssiz_t i = 0,
ECaseCompare cmp = kExact) const;
Ssiz_t Index(const TString &s, Ssiz_t i = 0,
ECaseCompare cmp = kExact) const;
Ssiz_t Index(const char *pat, Ssiz_t patlen, Ssiz_t i,
ECaseCompare cmp) const;
Ssiz_t Index(const TString &s, Ssiz_t patlen, Ssiz_t i,
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);
TString &Insert(Ssiz_t pos, const TString &s, Ssiz_t extent);
Bool_t IsAscii() const;
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; }
Bool_t IsWhitespace() const { return (Length() == CountChar(' ')); }
Ssiz_t Last(char c) const { return Pref()->Last(c); }
Ssiz_t Length() const { return Pref()->fNchars; }
Bool_t MaybeRegexp() const;
Bool_t MaybeWildcard() const;
TString &Prepend(const char *cs);
TString &Prepend(const char *cs, Ssiz_t n);
TString &Prepend(const TString &s);
TString &Prepend(const TString &s, Ssiz_t n);
TString &Prepend(char c, Ssiz_t rep = 1);
istream &ReadFile(istream &str);
istream &ReadLine(istream &str,
Bool_t skipWhite = kTRUE);
istream &ReadString(istream &str);
istream &ReadToDelim(istream &str, char delim = '\n');
istream &ReadToken(istream &str);
TString &Remove(Ssiz_t pos);
TString &Remove(Ssiz_t pos, Ssiz_t n);
TString &Remove(EStripType s, char c);
TString &Replace(Ssiz_t pos, Ssiz_t n, const char *s);
TString &Replace(Ssiz_t pos, Ssiz_t n, const char *s, Ssiz_t ns);
TString &Replace(Ssiz_t pos, Ssiz_t n, const TString &s);
TString &Replace(Ssiz_t pos, Ssiz_t n1, const TString &s, Ssiz_t n2);
TString &ReplaceAll(const TString &s1, const TString &s2);
TString &ReplaceAll(const TString &s1, const char *s2);
TString &ReplaceAll(const char *s1, const TString &s2);
TString &ReplaceAll(const char *s1, const char *s2);
TString &ReplaceAll(const char *s1, Ssiz_t ls1, const char *s2, Ssiz_t ls2);
void Resize(Ssiz_t n);
TSubString Strip(EStripType s = kTrailing, char c = ' ') const;
void ToLower();
void ToUpper();
TObjArray *Tokenize(const TString &delim) const;
Bool_t Tokenize(TString &tok, Ssiz_t &from, const char *delim = " ") const;
static UInt_t Hash(const void *txt, Int_t ntxt);
static Ssiz_t InitialCapacity(Ssiz_t ic = 15);
static Ssiz_t MaxWaste(Ssiz_t mw = 15);
static Ssiz_t ResizeIncrement(Ssiz_t ri = 16);
static Ssiz_t GetInitialCapacity();
static Ssiz_t GetResizeIncrement();
static Ssiz_t GetMaxWaste();
static TString Format(const char *fmt, ...);
ClassDef(TString,1)
};
istream &operator>>(istream &str, TString &s);
ostream &operator<<(ostream &str, const TString &s);
#if defined(R__TEMPLATE_OVERLOAD_BUG)
template <>
#endif
TBuffer &operator>>(TBuffer &buf, TString *&sp);
TString ToLower(const TString &s);
TString ToUpper(const TString &s);
inline UInt_t Hash(const TString &s) { return s.Hash(); }
inline UInt_t Hash(const TString *s) { return s->Hash(); }
UInt_t Hash(const char *s);
extern char *Form(const char *fmt, ...);
extern void Printf(const char *fmt, ...);
extern char *Strip(const char *str, char c = ' ');
extern char *StrDup(const char *str);
extern char *Compress(const char *str);
extern int EscChar(const char *src, char *dst, int dstlen, char *specchars,
char escchar);
extern int UnEscChar(const char *src, char *dst, int dstlen, char *specchars,
char escchar);
#ifdef NEED_STRCASECMP
extern int strcasecmp(const char *str1, const char *str2);
extern int strncasecmp(const char *str1, const char *str2, Ssiz_t n);
#endif
inline void TStringRef::UnLink()
{ if (RemoveReference() == 0) delete [] (char*)this; }
inline void TString::Cow()
{ if (Pref()->References() > 1) Clone(); }
inline void TString::Cow(Ssiz_t nc)
{ if (Pref()->References() > 1 || Capacity() < nc) Clone(nc); }
inline TString &TString::Append(const char *cs)
{ return Replace(Length(), 0, cs, cs ? strlen(cs) : 0); }
inline TString &TString::Append(const char *cs, Ssiz_t n)
{ return Replace(Length(), 0, cs, n); }
inline TString &TString::Append(const TString &s)
{ return Replace(Length(), 0, s.Data(), s.Length()); }
inline TString &TString::Append(const TString &s, Ssiz_t n)
{ return Replace(Length(), 0, s.Data(), TMath::Min(n, s.Length())); }
inline TString &TString::operator+=(const char *cs)
{ return Append(cs, cs ? strlen(cs) : 0); }
inline TString &TString::operator+=(const TString &s)
{ return Append(s.Data(), s.Length()); }
inline TString &TString::operator+=(char c)
{ return Append(c); }
inline TString &TString::operator+=(Long_t i)
{ char s[32]; sprintf(s, "%ld", i); return operator+=(s); }
inline TString &TString::operator+=(ULong_t i)
{ char s[32]; sprintf(s, "%lu", i); return operator+=(s); }
inline TString &TString::operator+=(Short_t i)
{ return operator+=((Long_t) i); }
inline TString &TString::operator+=(UShort_t i)
{ return operator+=((ULong_t) i); }
inline TString &TString::operator+=(Int_t i)
{ return operator+=((Long_t) i); }
inline TString &TString::operator+=(UInt_t i)
{ return operator+=((ULong_t) i); }
inline TString &TString::operator+=(Double_t f)
{ char s[32]; sprintf(s, "%9.9g", f); return operator+=(s); }
inline TString &TString::operator+=(Float_t f)
{ return operator+=((Double_t) f); }
inline TString &TString::operator+=(Long64_t l)
{ char s[32]; sprintf(s, "%lld", l); return operator+=(s); }
inline TString &TString::operator+=(ULong64_t ul)
{ char s[32]; sprintf(s, "%llu", ul); return operator+=(s); }
inline Bool_t TString::BeginsWith(const char *s, ECaseCompare cmp) const
{ return Index(s, s ? strlen(s) : (Ssiz_t)0, (Ssiz_t)0, cmp) == 0; }
inline Bool_t TString::BeginsWith(const TString &pat, ECaseCompare cmp) const
{ return Index(pat.Data(), pat.Length(), (Ssiz_t)0, cmp) == 0; }
inline Bool_t TString::Contains(const TString &pat, ECaseCompare cmp) const
{ return Index(pat.Data(), pat.Length(), (Ssiz_t)0, cmp) != kNPOS; }
inline Bool_t TString::Contains(const char *s, ECaseCompare cmp) const
{ return Index(s, s ? strlen(s) : 0, (Ssiz_t)0, cmp) != kNPOS; }
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); }
inline Ssiz_t TString::Index(const TString &s, Ssiz_t i, ECaseCompare cmp) const
{ return Index(s.Data(), s.Length(), i, cmp); }
inline Ssiz_t TString::Index(const TString &pat, Ssiz_t patlen, Ssiz_t i,
ECaseCompare cmp) const
{ return Index(pat.Data(), patlen, i, cmp); }
inline TString &TString::Insert(Ssiz_t pos, const char *cs)
{ return Replace(pos, 0, cs, cs ? strlen(cs) : 0); }
inline TString &TString::Insert(Ssiz_t pos, const char *cs, Ssiz_t n)
{ return Replace(pos, 0, cs, n); }
inline TString &TString::Insert(Ssiz_t pos, const TString &s)
{ return Replace(pos, 0, s.Data(), s.Length()); }
inline TString &TString::Insert(Ssiz_t pos, const TString &s, Ssiz_t n)
{ return Replace(pos, 0, s.Data(), TMath::Min(n, s.Length())); }
inline TString &TString::Prepend(const char *cs)
{ return Replace(0, 0, cs, cs ? strlen(cs) : 0); }
inline TString &TString::Prepend(const char *cs, Ssiz_t n)
{ return Replace(0, 0, cs, n); }
inline TString &TString::Prepend(const TString &s)
{ return Replace(0, 0, s.Data(), s.Length()); }
inline TString &TString::Prepend(const TString &s, Ssiz_t n)
{ return Replace(0, 0, s.Data(), TMath::Min(n, s.Length())); }
inline TString &TString::Remove(Ssiz_t pos)
{ return Replace(pos, TMath::Max(0, Length()-pos), 0, 0); }
inline TString &TString::Remove(Ssiz_t pos, Ssiz_t n)
{ return Replace(pos, n, 0, 0); }
inline TString &TString::Chop()
{ return Remove(TMath::Max(0, Length()-1)); }
inline TString &TString::Replace(Ssiz_t pos, Ssiz_t n, const char *cs)
{ return Replace(pos, n, cs, cs ? strlen(cs) : 0); }
inline TString &TString::Replace(Ssiz_t pos, Ssiz_t n, const TString& s)
{ return Replace(pos, n, s.Data(), s.Length()); }
inline TString &TString::Replace(Ssiz_t pos, Ssiz_t n1, const TString &s,
Ssiz_t n2)
{ return Replace(pos, n1, s.Data(), TMath::Min(s.Length(), n2)); }
inline TString &TString::ReplaceAll(const TString &s1, const TString &s2)
{ return ReplaceAll(s1.Data(), s1.Length(), s2.Data(), s2.Length()) ; }
inline TString &TString::ReplaceAll(const TString &s1, const char *s2)
{ return ReplaceAll(s1.Data(), s1.Length(), s2, s2 ? strlen(s2) : 0); }
inline TString &TString::ReplaceAll(const char *s1, const TString &s2)
{ return ReplaceAll(s1, s1 ? strlen(s1) : 0, s2.Data(), s2.Length()); }
inline TString &TString::ReplaceAll(const char *s1,const char *s2)
{ return ReplaceAll(s1, s1 ? strlen(s1) : 0, s2, s2 ? strlen(s2) : 0); }
inline char &TString::operator()(Ssiz_t i)
{ Cow(); return fData[i]; }
inline char TString::operator[](Ssiz_t i) const
{ AssertElement(i); return fData[i]; }
inline char TString::operator()(Ssiz_t i) const
{ return fData[i]; }
inline const char *TSubString::Data() const
{
return fStr.Data() + fBegin;
}
inline char TSubString::operator[](Ssiz_t i) const
{ AssertElement(i); return fStr.fData[fBegin+i]; }
inline char TSubString::operator()(Ssiz_t i) const
{ return fStr.fData[fBegin+i]; }
inline TSubString &TSubString::operator=(const TSubString &s)
{ fStr = s.fStr; fBegin = s.fBegin; fExtent = s.fExtent; return *this; }
#if !defined(R__ALPHA)
inline Bool_t operator==(const TString &s1, const TString &s2)
{
return ((s1.Length() == s2.Length()) &&
!memcmp(s1.Data(), s2.Data(), s1.Length()));
}
#endif
inline Bool_t operator!=(const TString &s1, const TString &s2)
{ return !(s1 == s2); }
inline Bool_t operator<(const TString &s1, const TString &s2)
{ return s1.CompareTo(s2) < 0; }
inline Bool_t operator>(const TString &s1, const TString &s2)
{ return s1.CompareTo(s2) > 0; }
inline Bool_t operator<=(const TString &s1, const TString &s2)
{ return s1.CompareTo(s2) <= 0; }
inline Bool_t operator>=(const TString &s1, const TString &s2)
{ return s1.CompareTo(s2) >= 0; }
inline Bool_t operator!=(const TString &s1, const char *s2)
{ return !(s1 == s2); }
inline Bool_t operator<(const TString &s1, const char *s2)
{ return s1.CompareTo(s2) < 0; }
inline Bool_t operator>(const TString &s1, const char *s2)
{ return s1.CompareTo(s2) > 0; }
inline Bool_t operator<=(const TString &s1, const char *s2)
{ return s1.CompareTo(s2) <= 0; }
inline Bool_t operator>=(const TString &s1, const char *s2)
{ return s1.CompareTo(s2) >= 0; }
inline Bool_t operator==(const char *s1, const TString &s2)
{ return (s2 == s1); }
inline Bool_t operator!=(const char *s1, const TString &s2)
{ return !(s2 == s1); }
inline Bool_t operator<(const char *s1, const TString &s2)
{ return s2.CompareTo(s1) > 0; }
inline Bool_t operator>(const char *s1, const TString &s2)
{ return s2.CompareTo(s1) < 0; }
inline Bool_t operator<=(const char *s1, const TString &s2)
{ return s2.CompareTo(s1) >= 0; }
inline Bool_t operator>=(const char *s1, const TString &s2)
{ return s2.CompareTo(s1) <= 0; }
inline Bool_t operator==(const TString &s1, const TSubString &s2)
{ return (s2 == s1); }
inline Bool_t operator==(const char *s1, const TSubString &s2)
{ return (s2 == s1); }
inline Bool_t operator!=(const TSubString &s1, const char *s2)
{ return !(s1 == s2); }
inline Bool_t operator!=(const TSubString &s1, const TString &s2)
{ return !(s1 == s2); }
inline Bool_t operator!=(const TSubString &s1, const TSubString &s2)
{ return !(s1 == s2); }
inline Bool_t operator!=(const TString &s1, const TSubString &s2)
{ return !(s2 == s1); }
inline Bool_t operator!=(const char *s1, const TSubString &s2)
{ return !(s2 == s1); }
#endif