ROOT » CORE » BASE » TSubString

class TSubString


Basic string class.

Cannot be stored in a TCollection... use TObjString instead.

The underlying string is stored as a char* that can be accessed via
TString provides Short String Optimization (SSO) so that short
strings (<15 on 64-bit and <11 on 32-bit) are contained in the
TString internal data structure without the need for mallocing the
required space.

Substring operations are provided by the TSubString class, which
holds a reference to the original string and its data, along with
the offset and length of the substring. To retrieve the substring
as a TString, construct a TString from it, eg:
root [0] TString s("hello world")
root [1] TString s2( s(0,5) )
root [2] s2
(class TString)"hello"

Function Members (Methods)

const char*Data() const
Bool_tIsNull() const
Ssiz_tLength() const
intoperator!() const
char&operator()(Ssiz_t i)
charoperator()(Ssiz_t i) const
TSubString&operator=(const char* s)
TSubString&operator=(const TString& s)
TSubString&operator=(const TSubString& s)
char&operator[](Ssiz_t i)
charoperator[](Ssiz_t i) const
Ssiz_tStart() const
TSubString(const TSubString& s)
voidAssertElement(Ssiz_t i) const
voidSubStringError(Ssiz_t, Ssiz_t, Ssiz_t) const
TSubString(const TString& s, Ssiz_t start, Ssiz_t len)

Data Members

Ssiz_tfBeginIndex of starting character
Ssiz_tfExtentLength of TSubString
TString&fStrReferenced string

Class Charts

Inheritance Chart:

Function documentation

TSubString(const TString& s, Ssiz_t start, Ssiz_t len)
 Private constructor.
char& operator[](Ssiz_t i)
 Return character at pos i from sub-string. Check validity of i.
char& operator()(Ssiz_t i)
 Return character at pos i from sub-string. No check on i.
TSubString& operator=(const TString& s)
 Assign string to sub-string.
TSubString& operator=(const char* s)
 Assign char* to sub-string.
void ToLower()
 Convert sub-string to lower-case.
void ToUpper()
 Convert sub-string to upper-case.
void SubStringError(Ssiz_t , Ssiz_t , Ssiz_t ) const
 Output error message.
void AssertElement(Ssiz_t i) const
 Check to make sure a sub-string index is in range.
const char * Data() const
 Return a pointer to the beginning of the substring. Note that the
 terminating null is in the same place as for the original
 TString, so this method is not appropriate for converting the
 TSubString to a string. To do that, construct a TString from the
 TSubString. For example:

   root [0] TString s("hello world")
   root [1] TSubString sub=s(0, 5)
   root [2] sub.Data()
   (const char* 0x857c8b8)"hello world"
   root [3] TString substr(sub)
   root [4] substr
   (class TString)"hello"
char operator[](Ssiz_t i) const
 Access to elements of sub-string with bounds checking
{ AssertElement(i); return fStr.GetPointer()[fBegin+i]; }
char operator()(Ssiz_t i) const
{ return fStr.GetPointer()[fBegin+i]; }
TSubString & operator=(const TSubString& s)
{ fStr = s.fStr; fBegin = s.fBegin; fExtent = s.fExtent; return *this; }
TSubString(const TString& s, Ssiz_t start, Ssiz_t len)
 NB: the only constructor is private
Ssiz_t Length() const
{ return fExtent; }
Ssiz_t Start() const
{ return fBegin; }
Bool_t IsNull() const
 For detecting null substrings
{ return fBegin == kNPOS; }
int operator!() const
{ return fBegin == kNPOS; }