Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

TString.h

Go to the documentation of this file.
00001 // @(#)root/base:$Name:  $:$Id: TString.h,v 1.21 2002/12/05 15:31:02 rdm Exp $
00002 // Author: Fons Rademakers   04/08/95
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 #ifndef ROOT_TString
00013 #define ROOT_TString
00014 
00015 
00017 //                                                                      //
00018 // TString                                                              //
00019 //                                                                      //
00020 // Basic string class.                                                  //
00021 //                                                                      //
00022 // Cannot be stored in a TCollection... use TObjString instead.         //
00023 //                                                                      //
00025 
00026 #ifndef __CINT__
00027 #include <string.h>
00028 #endif
00029 
00030 #ifndef ROOT_TMath
00031 #include "TMath.h"
00032 #endif
00033 
00034 #ifndef ROOT_TRefCnt
00035 #include "TRefCnt.h"
00036 #endif
00037 
00038 #ifndef ROOT_Riosfwd
00039 #include "Riosfwd.h"
00040 #endif
00041 
00042 #ifdef R__MWERKS
00043 #   ifdef Length
00044 #      undef Length
00045 #   endif
00046 #endif
00047 
00048 class TRegexp;
00049 class TString;
00050 class TSubString;
00051 
00052 TString operator+(const TString& s1, const TString& s2);
00053 TString operator+(const TString& s,  const char *cs);
00054 TString operator+(const char *cs, const TString& s);
00055 TString operator+(const TString& s, char c);
00056 TString operator+(const TString& s, Long_t i);
00057 TString operator+(const TString& s, ULong_t i);
00058 TString operator+(char c, const TString& s);
00059 TString operator+(Long_t i, const TString& s);
00060 TString operator+(ULong_t i, const TString& s);
00061 Bool_t  operator==(const TString& s1, const TString& s2);
00062 Bool_t  operator==(const TString& s1, const char *s2);
00063 Bool_t  operator==(const TSubString& s1, const TSubString& s2);
00064 Bool_t  operator==(const TSubString& s1, const TString& s2);
00065 Bool_t  operator==(const TSubString& s1, const char *s2);
00066 
00067 
00069 //                                                                      //
00070 //  TStringRef                                                          //
00071 //                                                                      //
00072 //  This is the dynamically allocated part of a TString.                //
00073 //  It maintains a reference count. It contains no public member        //
00074 //  functions.                                                          //
00075 //                                                                      //
00077 class TStringRef : public TRefCnt {
00078 
00079 friend class TString;
00080 friend class TStringLong;
00081 friend class TSubString;
00082 
00083 private:
00084    Ssiz_t       fCapacity;      // Max string length (excluding null)
00085    Ssiz_t       fNchars;        // String length (excluding null)
00086 
00087    void         UnLink(); // disconnect from a TStringRef, maybe delete it
00088 
00089    Ssiz_t       Length() const   { return fNchars; }
00090    Ssiz_t       Capacity() const { return fCapacity; }
00091    char        *Data() const     { return (char*)(this+1); }
00092 
00093    char&        operator[](Ssiz_t i)       { return ((char*)(this+1))[i]; }
00094    char         operator[](Ssiz_t i) const { return ((char*)(this+1))[i]; }
00095 
00096    Ssiz_t       First(char c) const;
00097    Ssiz_t       First(const char *s) const;
00098    unsigned     Hash() const;
00099    unsigned     HashFoldCase() const;
00100    Ssiz_t       Last(char) const;
00101 
00102    static TStringRef *GetRep(Ssiz_t capac, Ssiz_t nchar);
00103 };
00104 
00105 
00107 //                                                                      //
00108 //  TSubString                                                          //
00109 //                                                                      //
00110 //  The TSubString class allows selected elements to be addressed.      //
00111 //  There are no public constructors.                                   //
00112 //                                                                      //
00114 class TSubString {
00115 
00116 friend class TStringLong;
00117 friend class TString;
00118 
00119 friend Bool_t operator==(const TSubString& s1, const TSubString& s2);
00120 friend Bool_t operator==(const TSubString& s1, const TString& s2);
00121 friend Bool_t operator==(const TSubString& s1, const char *s2);
00122 
00123 private:
00124    TString      *fStr;           // Referenced string
00125    Ssiz_t        fBegin;         // Index of starting character
00126    Ssiz_t        fExtent;        // Length of TSubString
00127 
00128    // NB: the only constructor is private
00129    TSubString(const TString& s, Ssiz_t start, Ssiz_t len);
00130 
00131 protected:
00132    void          SubStringError(Ssiz_t, Ssiz_t, Ssiz_t) const;
00133    void          AssertElement(Ssiz_t i) const;  // Verifies i is valid index
00134 
00135 public:
00136    TSubString(const TSubString& s)
00137      : fStr(s.fStr), fBegin(s.fBegin), fExtent(s.fExtent) { }
00138 
00139    TSubString&   operator=(const char *s);       // Assignment to char*
00140    TSubString&   operator=(const TString& s);    // Assignment to TString
00141    char&         operator()(Ssiz_t i);           // Index with optional bounds checking
00142    char&         operator[](Ssiz_t i);           // Index with bounds checking
00143    char          operator()(Ssiz_t i) const;     // Index with optional bounds checking
00144    char          operator[](Ssiz_t i) const;     // Index with bounds checking
00145 
00146    const char   *Data() const;
00147    Ssiz_t        Length() const          { return fExtent; }
00148    Ssiz_t        Start() const           { return fBegin; }
00149    void          ToLower();              // Convert self to lower-case
00150    void          ToUpper();              // Convert self to upper-case
00151 
00152    // For detecting null substrings
00153    Bool_t        IsNull() const          { return fBegin == kNPOS; }
00154    int           operator!() const       { return fBegin == kNPOS; }
00155 };
00156 
00157 
00159 //                                                                      //
00160 //  TString                                                             //
00161 //                                                                      //
00163 class TString {
00164 
00165 friend class TSubString;
00166 friend class TStringRef;
00167 
00168 friend TString operator+(const TString& s1, const TString& s2);
00169 friend TString operator+(const TString& s,  const char *cs);
00170 friend TString operator+(const char *cs, const TString& s);
00171 friend TString operator+(const TString& s, char c);
00172 friend TString operator+(const TString& s, Long_t i);
00173 friend TString operator+(const TString& s, ULong_t i);
00174 friend TString operator+(char c, const TString& s);
00175 friend TString operator+(Long_t i, const TString& s);
00176 friend TString operator+(ULong_t i, const TString& s);
00177 friend Bool_t  operator==(const TString& s1, const TString& s2);
00178 friend Bool_t  operator==(const TString& s1, const char *s2);
00179 
00180 private:
00181    static Ssiz_t  fgInitialCapac;   // Initial allocation Capacity
00182    static Ssiz_t  fgResizeInc;      // Resizing increment
00183    static Ssiz_t  fgFreeboard;      // Max empty space before reclaim
00184 
00185    void           Clone();          // Make self a distinct copy
00186    void           Clone(Ssiz_t nc); // Make self a distinct copy w. capacity nc
00187 
00188 protected:
00189    char          *fData;          // ref. counted data (TStringRef is in front)
00190 
00191    // Special concatenation constructor
00192    TString(const char *a1, Ssiz_t n1, const char *a2, Ssiz_t n2);
00193    TStringRef    *Pref() const { return (((TStringRef*) fData) - 1); }
00194    void           AssertElement(Ssiz_t nc) const; // Index in range
00195    void           Clobber(Ssiz_t nc);             // Remove old contents
00196    void           Cow();                          // Do copy on write as needed
00197    void           Cow(Ssiz_t nc);                 // Do copy on write as needed
00198    static Ssiz_t  AdjustCapacity(Ssiz_t nc);
00199    void           InitChar(char c);               // Initialize from char
00200 
00201 public:
00202    enum EStripType   { kLeading = 0x1, kTrailing = 0x2, kBoth = 0x3 };
00203    enum ECaseCompare { kExact, kIgnoreCase };
00204 
00205    TString();                       // Null string
00206    TString(Ssiz_t ic);              // Suggested capacity
00207    TString(const TString& s)        // Copy constructor
00208       { fData = s.fData; Pref()->AddReference(); }
00209 
00210    TString(const char *s);              // Copy to embedded null
00211    TString(const char *s, Ssiz_t n);    // Copy past any embedded nulls
00212    TString(char c) { InitChar(c); }
00213 
00214    TString(char c, Ssiz_t s);
00215 
00216    TString(const TSubString& sub);
00217 
00218    virtual ~TString();
00219 
00220    // ROOT I/O interface
00221    virtual void     FillBuffer(char *&buffer);
00222    virtual void     ReadBuffer(char *&buffer);
00223    virtual Int_t    Sizeof() const;
00224 
00225    static TString  *ReadString(TBuffer &b, const TClass *clReq);
00226    static void      WriteString(TBuffer &b, const TString *a);
00227 
00228    friend TBuffer &operator<<(TBuffer &b, const TString *obj);
00229 
00230    // Type conversion
00231    operator const char*() const { return fData; }
00232 
00233    // Assignment
00234    TString&    operator=(char s);                // Replace string
00235    TString&    operator=(const char *s);
00236    TString&    operator=(const TString& s);
00237    TString&    operator=(const TSubString& s);
00238    TString&    operator+=(const char *s);        // Append string
00239    TString&    operator+=(const TString& s);
00240    TString&    operator+=(char c);
00241    TString&    operator+=(Short_t i);
00242    TString&    operator+=(UShort_t i);
00243    TString&    operator+=(Int_t i);
00244    TString&    operator+=(UInt_t i);
00245    TString&    operator+=(Long_t i);
00246    TString&    operator+=(ULong_t i);
00247    TString&    operator+=(Float_t f);
00248    TString&    operator+=(Double_t f);
00249 
00250    // Indexing operators
00251    char&         operator[](Ssiz_t i);         // Indexing with bounds checking
00252    char&         operator()(Ssiz_t i);         // Indexing with optional bounds checking
00253    TSubString    operator()(Ssiz_t start, Ssiz_t len);   // Sub-string operator
00254    TSubString    operator()(const TRegexp& re);          // Match the RE
00255    TSubString    operator()(const TRegexp& re, Ssiz_t start);
00256    TSubString    SubString(const char *pat, Ssiz_t start = 0,
00257                            ECaseCompare cmp = kExact);
00258    char          operator[](Ssiz_t i) const;
00259    char          operator()(Ssiz_t i) const;
00260    TSubString    operator()(Ssiz_t start, Ssiz_t len) const;
00261    TSubString    operator()(const TRegexp& re) const;   // Match the RE
00262    TSubString    operator()(const TRegexp& re, Ssiz_t start) const;
00263    TSubString    SubString(const char *pat, Ssiz_t start = 0,
00264                            ECaseCompare cmp = kExact) const;
00265 
00266    // Non-static member functions
00267    TString&     Append(const char *cs);
00268    TString&     Append(const char *cs, Ssiz_t n);
00269    TString&     Append(const TString& s);
00270    TString&     Append(const TString& s, Ssiz_t n);
00271    TString&     Append(char c, Ssiz_t rep = 1);   // Append c rep times
00272    Bool_t       BeginsWith(const char *s,      ECaseCompare cmp = kExact) const;
00273    Bool_t       BeginsWith(const TString& pat, ECaseCompare cmp = kExact) const;
00274    Ssiz_t       Capacity() const         { return Pref()->Capacity(); }
00275    Ssiz_t       Capacity(Ssiz_t n);
00276    TString&     Chop();
00277    int          CompareTo(const char *cs,    ECaseCompare cmp = kExact) const;
00278    int          CompareTo(const TString& st, ECaseCompare cmp = kExact) const;
00279    Bool_t       Contains(const char *pat,    ECaseCompare cmp = kExact) const;
00280    Bool_t       Contains(const TString& pat, ECaseCompare cmp = kExact) const;
00281    Bool_t       Contains(const TRegexp& pat) const;
00282    Int_t        CountChar(Int_t c) const;
00283    TString      Copy() const;
00284    const char  *Data() const                 { return fData; }
00285    Bool_t       EndsWith(const char *pat,    ECaseCompare cmp = kExact) const;
00286    Ssiz_t       First(char c) const          { return Pref()->First(c); }
00287    Ssiz_t       First(const char *cs) const  { return Pref()->First(cs); }
00288    unsigned     Hash(ECaseCompare cmp = kExact) const;
00289    Ssiz_t       Index(const char *pat, Ssiz_t i = 0,
00290                       ECaseCompare cmp = kExact) const;
00291    Ssiz_t       Index(const TString& s, Ssiz_t i = 0,
00292                       ECaseCompare cmp = kExact) const;
00293    Ssiz_t       Index(const char *pat, Ssiz_t patlen, Ssiz_t i,
00294                       ECaseCompare cmp) const;
00295    Ssiz_t       Index(const TString& s, Ssiz_t patlen, Ssiz_t i,
00296                       ECaseCompare cmp) const;
00297    Ssiz_t       Index(const TRegexp& pat, Ssiz_t i = 0) const;
00298    Ssiz_t       Index(const TRegexp& pat, Ssiz_t *ext, Ssiz_t i = 0) const;
00299    TString&     Insert(Ssiz_t pos, const char *s);
00300    TString&     Insert(Ssiz_t pos, const char *s, Ssiz_t extent);
00301    TString&     Insert(Ssiz_t pos, const TString& s);
00302    TString&     Insert(Ssiz_t pos, const TString& s, Ssiz_t extent);
00303    Bool_t       IsAscii() const;
00304    Bool_t       IsNull() const              { return Pref()->fNchars == 0; }
00305    Ssiz_t       Last(char c) const          { return Pref()->Last(c); }
00306    Ssiz_t       Length() const              { return Pref()->fNchars; }
00307    Bool_t       MaybeRegexp();
00308    TString&     Prepend(const char *cs);     // Prepend a character string
00309    TString&     Prepend(const char *cs, Ssiz_t n);
00310    TString&     Prepend(const TString& s);
00311    TString&     Prepend(const TString& s, Ssiz_t n);
00312    TString&     Prepend(char c, Ssiz_t rep = 1);  // Prepend c rep times
00313    istream&     ReadFile(istream& str);      // Read to EOF or null character
00314    istream&     ReadLine(istream& str,
00315                          Bool_t skipWhite = kTRUE);   // Read to EOF or newline
00316    istream&     ReadString(istream& str);             // Read to EOF or null character
00317    istream&     ReadToDelim(istream& str, char delim = '\n'); // Read to EOF or delimitor
00318    istream&     ReadToken(istream& str);                // Read separated by white space
00319    TString&     Remove(Ssiz_t pos);                     // Remove pos to end of string
00320    TString&     Remove(Ssiz_t pos, Ssiz_t n);           // Remove n chars starting at pos
00321    TString&     Replace(Ssiz_t pos, Ssiz_t n, const char *s);
00322    TString&     Replace(Ssiz_t pos, Ssiz_t n, const char *s, Ssiz_t ns);
00323    TString&     Replace(Ssiz_t pos, Ssiz_t n, const TString& s);
00324    TString&     Replace(Ssiz_t pos, Ssiz_t n1, const TString& s, Ssiz_t n2);
00325    TString&     ReplaceAll(const TString& s1, const TString& s2); // Find&Replace all s1 with s2 if any
00326    TString&     ReplaceAll(const TString& s1, const char *s2);    // Find&Replace all s1 with s2 if any
00327    TString&     ReplaceAll(const    char *s1, const TString& s2); // Find&Replace all s1 with s2 if any
00328    TString&     ReplaceAll(const char *s1, const char *s2);       // Find&Replace all s1 with s2 if any
00329    TString&     ReplaceAll(const char *s1, Ssiz_t ls1, const char *s2, Ssiz_t ls2);  // Find&Replace all s1 with s2 if any
00330    void         Resize(Ssiz_t n);                       // Truncate or add blanks as necessary
00331    TSubString   Strip(EStripType s = kTrailing, char c = ' ');
00332    TSubString   Strip(EStripType s = kTrailing, char c = ' ') const;
00333    void         ToLower();                              // Change self to lower-case
00334    void         ToUpper();                              // Change self to upper-case
00335 
00336    // Static member functions
00337    static Ssiz_t  InitialCapacity(Ssiz_t ic = 15);      // Initial allocation capacity
00338    static Ssiz_t  MaxWaste(Ssiz_t mw = 15);             // Max empty space before reclaim
00339    static Ssiz_t  ResizeIncrement(Ssiz_t ri = 16);      // Resizing increment
00340    static Ssiz_t  GetInitialCapacity();
00341    static Ssiz_t  GetResizeIncrement();
00342    static Ssiz_t  GetMaxWaste();
00343 
00344    ClassDef(TString,1)  //Basic string class
00345 };
00346 
00347 // Related global functions
00348 istream&  operator>>(istream& str,       TString&   s);
00349 ostream&  operator<<(ostream& str, const TString&   s);
00350 TBuffer&  operator>>(TBuffer& buf,       TString&   s);
00351 TBuffer&  operator<<(TBuffer& buf, const TString&   s);
00352 #if defined(R__TEMPLATE_OVERLOAD_BUG)
00353 template <>
00354 #endif
00355 TBuffer&  operator>>(TBuffer& buf,       TString*& sp);
00356 
00357 TString ToLower(const TString&);    // Return lower-case version of argument
00358 TString ToUpper(const TString&);    // Return upper-case version of argument
00359 inline  unsigned Hash(const TString& s) { return s.Hash(); }
00360 inline  unsigned Hash(const TString *s) { return s->Hash(); }
00361         unsigned Hash(const char *s);
00362 
00363 extern char *Form(const char *fmt, ...);     // format in circular buffer
00364 extern void  Printf(const char *fmt, ...);   // format and print
00365 extern char *Strip(const char *str, char c = ' '); // strip c off str, free with delete []
00366 extern char *StrDup(const char *str);        // duplicate str, free with delete []
00367 extern char *Compress(const char *str);      // remove blanks from string, free with delele []
00368 extern int   EscChar(const char *src, char *dst, int dstlen, char *specchars,
00369                      char escchar);          // copy from src to dst escaping specchars by escchar
00370 extern int   UnEscChar(const char *src, char *dst, int dstlen, char *specchars,
00371                      char escchar);          // copy from src to dst removing escchar from specchars
00372 
00373 #ifdef NEED_STRCASECMP
00374 extern int strcasecmp(const char *str1, const char *str2);
00375 extern int strncasecmp(const char *str1, const char *str2, Ssiz_t n);
00376 #endif
00377 
00378 
00380 //                                                                      //
00381 //  Inlines                                                             //
00382 //                                                                      //
00384 
00385 inline void TStringRef::UnLink()
00386 { if (RemoveReference() == 0) delete [] (char*)this; }
00387 
00388 inline void TString::Cow()
00389 { if (Pref()->References() > 1) Clone(); }
00390 
00391 inline void TString::Cow(Ssiz_t nc)
00392 { if (Pref()->References() > 1  || Capacity() < nc) Clone(nc); }
00393 
00394 inline TString& TString::Append(const char *cs)
00395 { return Replace(Length(), 0, cs, strlen(cs)); }
00396 
00397 inline TString& TString::Append(const char* cs, Ssiz_t n)
00398 { return Replace(Length(), 0, cs, n); }
00399 
00400 inline TString& TString::Append(const TString& s)
00401 { return Replace(Length(), 0, s.Data(), s.Length()); }
00402 
00403 inline TString& TString::Append(const TString& s, Ssiz_t n)
00404 { return Replace(Length(), 0, s.Data(), TMath::Min(n, s.Length())); }
00405 
00406 inline TString& TString::operator+=(const char* cs)
00407 { return Append(cs, strlen(cs)); }
00408 
00409 inline TString& TString::operator+=(const TString& s)
00410 { return Append(s.Data(), s.Length()); }
00411 
00412 inline TString& TString::operator+=(char c)
00413 { return Append(c); }
00414 
00415 inline TString& TString::operator+=(Long_t i)
00416 { return operator+=(Form("%ld", i)); }
00417 
00418 inline TString& TString::operator+=(ULong_t i)
00419 { return operator+=(Form("%lu", i)); }
00420 
00421 inline TString& TString::operator+=(Short_t i)
00422 { return operator+=((Long_t) i); }
00423 
00424 inline TString& TString::operator+=(UShort_t i)
00425 { return operator+=((ULong_t) i); }
00426 
00427 inline TString& TString::operator+=(Int_t i)
00428 { return operator+=((Long_t) i); }
00429 
00430 inline TString& TString::operator+=(UInt_t i)
00431 { return operator+=((ULong_t) i); }
00432 
00433 inline TString& TString::operator+=(Double_t f)
00434 { return operator+=(Form("%9.9g", f)); }
00435 
00436 inline TString& TString::operator+=(Float_t f)
00437 { return operator+=((Double_t) f); }
00438 
00439 inline Bool_t TString::BeginsWith(const char* s, ECaseCompare cmp) const
00440 { return Index(s, strlen(s), (Ssiz_t)0, cmp) == 0; }
00441 
00442 inline Bool_t TString::BeginsWith(const TString& pat, ECaseCompare cmp) const
00443 { return Index(pat.Data(), pat.Length(), (Ssiz_t)0, cmp) == 0; }
00444 
00445 inline Bool_t TString::Contains(const TString& pat, ECaseCompare cmp) const
00446 { return Index(pat.Data(), pat.Length(), (Ssiz_t)0, cmp) != kNPOS; }
00447 
00448 inline Bool_t TString::Contains(const char* s, ECaseCompare cmp) const
00449 { return Index(s, strlen(s), (Ssiz_t)0, cmp) != kNPOS; }
00450 
00451 inline Bool_t TString::Contains(const TRegexp& pat) const
00452 { return Index(pat, (Ssiz_t)0) != kNPOS; }
00453 
00454 inline Ssiz_t TString::Index(const char* s, Ssiz_t i, ECaseCompare cmp) const
00455 { return Index(s, strlen(s), i, cmp); }
00456 
00457 inline Ssiz_t TString::Index(const TString& s, Ssiz_t i, ECaseCompare cmp) const
00458 { return Index(s.Data(), s.Length(), i, cmp); }
00459 
00460 inline Ssiz_t TString::Index(const TString& pat, Ssiz_t patlen, Ssiz_t i,
00461                              ECaseCompare cmp) const
00462 { return Index(pat.Data(), patlen, i, cmp); }
00463 
00464 inline TString& TString::Insert(Ssiz_t pos, const char* cs)
00465 { return Replace(pos, 0, cs, strlen(cs)); }
00466 
00467 inline TString& TString::Insert(Ssiz_t pos, const char* cs, Ssiz_t n)
00468 { return Replace(pos, 0, cs, n); }
00469 
00470 inline TString& TString::Insert(Ssiz_t pos, const TString& s)
00471 { return Replace(pos, 0, s.Data(), s.Length()); }
00472 
00473 inline TString& TString::Insert(Ssiz_t pos, const TString& s, Ssiz_t n)
00474 { return Replace(pos, 0, s.Data(), TMath::Min(n, s.Length())); }
00475 
00476 inline TString& TString::Prepend(const char* cs)
00477 { return Replace(0, 0, cs, strlen(cs)); }
00478 
00479 inline TString& TString::Prepend(const char* cs, Ssiz_t n)
00480 { return Replace(0, 0, cs, n); }
00481 
00482 inline TString& TString::Prepend(const TString& s)
00483 { return Replace(0, 0, s.Data(), s.Length()); }
00484 
00485 inline TString& TString::Prepend(const TString& s, Ssiz_t n)
00486 { return Replace(0, 0, s.Data(), TMath::Min(n, s.Length())); }
00487 
00488 inline TString& TString::Remove(Ssiz_t pos)
00489 { return Replace(pos, TMath::Max(0, Length()-pos), 0, 0); }
00490 
00491 inline TString& TString::Remove(Ssiz_t pos, Ssiz_t n)
00492 { return Replace(pos, n, 0, 0); }
00493 
00494 inline TString& TString::Chop()
00495 { return Remove(TMath::Max(0,Length()-1)); }
00496 
00497 inline TString& TString::Replace(Ssiz_t pos, Ssiz_t n, const char* cs)
00498 { return Replace(pos, n, cs, strlen(cs)); }
00499 
00500 inline TString& TString::Replace(Ssiz_t pos, Ssiz_t n, const TString& s)
00501 { return Replace(pos, n, s.Data(), s.Length()); }
00502 
00503 inline TString& TString::Replace(Ssiz_t pos, Ssiz_t n1, const TString& s,
00504                                  Ssiz_t n2)
00505 { return Replace(pos, n1, s.Data(), TMath::Min(s.Length(), n2)); }
00506 
00507 inline TString&  TString::ReplaceAll(const TString& s1,const TString& s2)
00508 { return ReplaceAll( s1.Data(), s1.Length(), s2.Data(), s2.Length()) ; }
00509 
00510 inline TString&  TString::ReplaceAll(const TString& s1,const char *s2)
00511 { return ReplaceAll( s1.Data(), s1.Length(), s2, s2 ? strlen(s2):0) ; }
00512 
00513 inline TString&  TString::ReplaceAll(const char *s1,const TString& s2)
00514 { return ReplaceAll( s1, s1 ? strlen(s1): 0, s2.Data(), s2.Length()) ; }
00515 
00516 inline TString&  TString::ReplaceAll(const char *s1,const char *s2)
00517 { return ReplaceAll( s1, s1?strlen(s1):0, s2, s2?strlen(s2):0) ; }
00518 
00519 inline char& TString::operator()(Ssiz_t i)
00520 { Cow(); return fData[i]; }
00521 
00522 inline char TString::operator[](Ssiz_t i) const
00523 { AssertElement(i); return fData[i]; }
00524 
00525 inline char TString::operator()(Ssiz_t i) const
00526 { return fData[i]; }
00527 
00528 inline const char* TSubString::Data() const
00529 { return fStr->Data() + fBegin; }
00530 
00531 // Access to elements of sub-string with bounds checking
00532 inline char TSubString::operator[](Ssiz_t i) const
00533 { AssertElement(i); return fStr->fData[fBegin+i]; }
00534 
00535 inline char TSubString::operator()(Ssiz_t i) const
00536 { return fStr->fData[fBegin+i]; }
00537 
00538 // String Logical operators
00539 #if !defined(R__MWERKS) && !defined(R__ALPHA)
00540 inline Bool_t     operator==(const TString& s1, const TString& s2)
00541 {
00542    return ((s1.Length() == s2.Length()) &&
00543             !memcmp(s1.Data(), s2.Data(), s1.Length()));
00544 }
00545 #endif
00546 
00547 inline Bool_t     operator!=(const TString& s1, const TString& s2)
00548 { return !(s1 == s2); }
00549 
00550 inline Bool_t     operator< (const TString& s1, const TString& s2)
00551 { return s1.CompareTo(s2)< 0; }
00552 
00553 inline Bool_t     operator> (const TString& s1, const TString& s2)
00554 { return s1.CompareTo(s2)> 0; }
00555 
00556 inline Bool_t     operator<=(const TString& s1, const TString& s2)
00557 { return s1.CompareTo(s2)<=0; }
00558 
00559 inline Bool_t     operator>=(const TString& s1, const TString& s2)
00560 { return s1.CompareTo(s2)>=0; }
00561 
00562 //     Bool_t     operator==(const TString& s1, const char* s2);
00563 inline Bool_t     operator!=(const TString& s1, const char* s2)
00564 { return !(s1 == s2); }
00565 
00566 inline Bool_t     operator< (const TString& s1, const char* s2)
00567 { return s1.CompareTo(s2)< 0; }
00568 
00569 inline Bool_t     operator> (const TString& s1, const char* s2)
00570 { return s1.CompareTo(s2)> 0; }
00571 
00572 inline Bool_t     operator<=(const TString& s1, const char* s2)
00573 { return s1.CompareTo(s2)<=0; }
00574 
00575 inline Bool_t     operator>=(const TString& s1, const char* s2)
00576 { return s1.CompareTo(s2)>=0; }
00577 
00578 inline Bool_t     operator==(const char* s1, const TString& s2)
00579 { return (s2 == s1); }
00580 
00581 inline Bool_t     operator!=(const char* s1, const TString& s2)
00582 { return !(s2 == s1); }
00583 
00584 inline Bool_t     operator< (const char* s1, const TString& s2)
00585 { return s2.CompareTo(s1)> 0; }
00586 
00587 inline Bool_t     operator> (const char* s1, const TString& s2)
00588 { return s2.CompareTo(s1)< 0; }
00589 
00590 inline Bool_t     operator<=(const char* s1, const TString& s2)
00591 { return s2.CompareTo(s1)>=0; }
00592 
00593 inline Bool_t     operator>=(const char* s1, const TString& s2)
00594 { return s2.CompareTo(s1)<=0; }
00595 
00596 // SubString Logical operators
00597 //     Bool_t     operator==(const TSubString& s1, const TSubString& s2);
00598 //     Bool_t     operator==(const TSubString& s1, const char* s2);
00599 //     Bool_t     operator==(const TSubString& s1, const TString& s2);
00600 inline Bool_t     operator==(const TString& s1,    const TSubString& s2)
00601 { return (s2 == s1); }
00602 
00603 inline Bool_t     operator==(const char* s1, const TSubString& s2)
00604 { return (s2 == s1); }
00605 
00606 inline Bool_t     operator!=(const TSubString& s1, const char* s2)
00607 { return !(s1 == s2); }
00608 
00609 inline Bool_t     operator!=(const TSubString& s1, const TString& s2)
00610 { return !(s1 == s2); }
00611 
00612 inline Bool_t     operator!=(const TSubString& s1, const TSubString& s2)
00613 { return !(s1 == s2); }
00614 
00615 inline Bool_t     operator!=(const TString& s1,   const TSubString& s2)
00616 { return !(s2 == s1); }
00617 
00618 inline Bool_t     operator!=(const char* s1,       const TSubString& s2)
00619 { return !(s2 == s1); }
00620 
00621 #endif
00622 

Generated on Thu Dec 18 14:52:24 2003 for ROOT by doxygen1.2.16