KaliVeda  1.13/01
Heavy-Ion Analysis Toolkit
List of all members | Public Member Functions | Static Public Member Functions | Protected Attributes | List of all members
KVString Class Reference

Extension of ROOT TString class which allows backwards compatibility with ROOT v3.10/02 onwards.

Tokenize() and IsDigit() methods are added here if they don't exist in the version of ROOT being used.

IsFloat() method is added: returns true if string is a floating-point number, i.e. if it has any of following formats (only first one returns kTRUE with TString::IsDigit()):

64320
6.4320 6,4320
6.43e20 6.43E20 6,43e20
6.43e-20 6.43E-20 6,43e-20
#define e(i)

Also Atoi() and Atof() are extended to include the following possibilities:

Begin(), Next() and End() can be used to loop over items in a string separated by the delimiter character given as argument to Begin().

Example:

KVString str("First | Second | Third");
str.Begin("|");
while( !str.End() ){
cout << str.Next().Data() << endl;
}
#define str(s)
Definition: KVBase.cpp:57
Extension of ROOT TString class which allows backwards compatibility with ROOT v3....
Definition: KVString.h:72

This will give the following output:

Second
Third
Ssiz_t First(char c) const

or, if Next() is called with argument strip_whitespace=kTRUE,

Second
Third

Definition at line 72 of file KVString.h.

Public Member Functions

 KVString ()
 
 KVString (const Char_t *s)
 
 KVString (const KVString &s)
 
 KVString (const TString &s)
 
 KVString (Double_t value, Double_t error)
 
virtual ~ KVString ()
 
void Begin (TString delim) const
 
void Capitalize ()
 Change first character of string from lower to upper case. More...
 
Bool_t End () const
 
KVStringFindCommonCharacters (const TCollection *, const char bug=' *')
 
KVStringFindCommonTitleCharacters (const TCollection *, const char bug=' *')
 
Int_t GetNValues (TString delim) const
 
virtual Bool_t Match (TString pattern)
 
KVString Next (Bool_t strip_whitespace=kFALSE) const
 
KVStringoperator= (const char *s)
 
KVStringoperator= (const KVString &s)
 
KVStringoperator= (const TString &s)
 
void RandomLetterSequence (Int_t length)
 
void RBegin (TString delim) const
 
void RemoveAllExtraWhiteSpace ()
 
KVString RNext (Bool_t strip_whitespace=kFALSE) const
 
virtual Int_t Sscanf (const Char_t *fmt,...)
 
KVString StripAllExtraWhiteSpace () const
 
virtual KVStringSubstitute (const Char_t c1, const Char_t c2)
 Replace every occurence of 'c1' with 'c2'. More...
 
std::vector< KVStringVectorize (TString delim, Bool_t strip_whitespace=kFALSE)
 
- Public Member Functions inherited from TString
 TString ()
 
 TString (char c)
 
 TString (char c, Ssiz_t s)
 
 TString (const char *s)
 
 TString (const char *s, Ssiz_t n)
 
 TString (const std::string &s)
 
 TString (const std::string_view &sub)
 
 TString (const TString &s)
 
 TString (const TSubString &sub)
 
 TString (Ssiz_t ic)
 
 TString (TString &&s) noexcept
 
virtual ~TString ()
 
TStringAppend (char c, Ssiz_t rep=1)
 
TStringAppend (const char *cs)
 
TStringAppend (const char *cs, Ssiz_t n)
 
TStringAppend (const TString &s)
 
TStringAppend (const TString &s, Ssiz_t n)
 
Double_t Atof () const
 
Int_t Atoi () const
 
Long64_t Atoll () 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
 
Ssiz_t Capacity (Ssiz_t n)
 
TStringChop ()
 
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 TRegexp &pat) const
 
Bool_t Contains (const TString &pat, ECaseCompare cmp=kExact) const
 
Bool_t Contains (TPRegexp &pat) const
 
TString Copy () const
 
Int_t CountChar (Int_t c) const
 
const char * Data () const
 
Bool_t EndsWith (const char *pat, ECaseCompare cmp=kExact) const
 
Bool_t EqualTo (const char *cs, ECaseCompare cmp=kExact) const
 
Bool_t EqualTo (const TString &st, ECaseCompare cmp=kExact) const
 
virtual void FillBuffer (char *&buffer) const
 
Ssiz_t First (char c) const
 
Ssiz_t First (const char *cs) const
 
void Form (const char *fmt,...)
 
Bool_t Gets (FILE *fp, Bool_t chop=kTRUE)
 
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 char *pat, Ssiz_t patlen, Ssiz_t i, ECaseCompare cmp) const
 
Ssiz_t Index (const TRegexp &pat, Ssiz_t *ext, Ssiz_t i=0) const
 
Ssiz_t Index (const TRegexp &pat, Ssiz_t i=0) const
 
Ssiz_t Index (const TString &s, Ssiz_t i=0, ECaseCompare cmp=kExact) const
 
Ssiz_t Index (const TString &s, Ssiz_t patlen, Ssiz_t i, ECaseCompare cmp) const
 
Ssiz_t Index (TPRegexp &pat, Ssiz_t *ext, Ssiz_t i=0) const
 
Ssiz_t Index (TPRegexp &pat, Ssiz_t i=0) const
 
TStringInsert (Ssiz_t pos, const char *s)
 
TStringInsert (Ssiz_t pos, const char *s, Ssiz_t extent)
 
TStringInsert (Ssiz_t pos, const TString &s)
 
TStringInsert (Ssiz_t pos, const TString &s, Ssiz_t extent)
 
Bool_t IsAlnum () const
 
Bool_t IsAlpha () const
 
Bool_t IsAscii () const
 
Bool_t IsBin () const
 
Bool_t IsDec () const
 
Bool_t IsDigit () const
 
Bool_t IsFloat () const
 
Bool_t IsHex () const
 
Bool_t IsInBaseN (Int_t base) const
 
Bool_t IsNull () const
 
Bool_t IsOct () const
 
Bool_t IsWhitespace () const
 
Ssiz_t Last (char c) const
 
Ssiz_t Length () const
 
Bool_t MaybeRegexp () const
 
Bool_t MaybeWildcard () const
 
TString MD5 () const
 
 operator const char * () const
 
 operator ROOT::Internal::TStringView () const
 
TSubString operator() (const TRegexp &re) const
 
TSubString operator() (const TRegexp &re, Ssiz_t start) const
 
char & operator() (Ssiz_t i)
 
char operator() (Ssiz_t i) const
 
TSubString operator() (Ssiz_t start, Ssiz_t len) const
 
TSubString operator() (TPRegexp &re) const
 
TSubString operator() (TPRegexp &re, Ssiz_t start) const
 
TStringoperator+= (char c)
 
TStringoperator+= (const char *s)
 
TStringoperator+= (const TString &s)
 
std::enable_if< ROOT::TypeTraits::IsFloatNumeral< T >::value, TString >::typeoperator+= (T f)
 
std::enable_if< ROOT::TypeTraits::IsSignedNumeral< T >::value, TString >::typeoperator+= (T i)
 
std::enable_if< ROOT::TypeTraits::IsUnsignedNumeral< T >::value, TString >::typeoperator+= (T u)
 
TStringoperator= (char s)
 
TStringoperator= (const char *s)
 
TStringoperator= (const std::string &s)
 
TStringoperator= (const std::string_view &s)
 
TStringoperator= (const TString &s)
 
TStringoperator= (const TSubString &s)
 
TStringoperator= (TString &&s) noexcept
 
char & operator[] (Ssiz_t i)
 
char operator[] (Ssiz_t i) const
 
TStringPrepend (char c, Ssiz_t rep=1)
 
TStringPrepend (const char *cs)
 
TStringPrepend (const char *cs, Ssiz_t n)
 
TStringPrepend (const TString &s)
 
TStringPrepend (const TString &s, Ssiz_t n)
 
void Puts (FILE *fp)
 
virtual void ReadBuffer (char *&buffer)
 
std::istream & ReadFile (std::istream &str)
 
std::istream & ReadLine (std::istream &str, Bool_t skipWhite=kTRUE)
 
std::istream & ReadString (std::istream &str)
 
std::istream & ReadToDelim (std::istream &str, char delim='\n')
 
std::istream & ReadToken (std::istream &str)
 
TStringRemove (EStripType s, char c)
 
TStringRemove (Ssiz_t pos)
 
TStringRemove (Ssiz_t pos, Ssiz_t n)
 
TStringReplace (Ssiz_t pos, Ssiz_t n, const char *s)
 
TStringReplace (Ssiz_t pos, Ssiz_t n, const char *s, Ssiz_t ns)
 
TStringReplace (Ssiz_t pos, Ssiz_t n, const TString &s)
 
TStringReplace (Ssiz_t pos, Ssiz_t n1, const TString &s, Ssiz_t n2)
 
TStringReplaceAll (const char *s1, const char *s2)
 
TStringReplaceAll (const char *s1, const TString &s2)
 
TStringReplaceAll (const char *s1, Ssiz_t ls1, const char *s2, Ssiz_t ls2)
 
TStringReplaceAll (const TString &s1, const char *s2)
 
TStringReplaceAll (const TString &s1, const TString &s2)
 
void Resize (Ssiz_t n)
 
virtual Int_t Sizeof () const
 
TSubString Strip (EStripType s=kTrailing, char c=' ') const
 
TSubString SubString (const char *pat, Ssiz_t start=0, ECaseCompare cmp=kExact) const
 
TStringSwap (TString &other)
 
TObjArrayTokenize (const TString &delim) const
 
Bool_t Tokenize (TString &tok, Ssiz_t &from, const char *delim=" ") const
 
void ToLower ()
 
void ToUpper ()
 
std::string_view View () const
 

Static Public Member Functions

static KVString BaseConvert (const KVString &s_in, Int_t base_in, Int_t base_out)
 
static KVString Itoa (Int_t value, Int_t base)
 
static KVString LLtoa (Long64_t value, Int_t base)
 
static KVString UItoa (UInt_t value, Int_t base)
 
static KVString ULLtoa (ULong64_t value, Int_t base)
 
- Static Public Member Functions inherited from TString
static TString BaseConvert (const TString &s_in, Int_t base_in, Int_t base_out)
 
static TString Format (const char *fmt,...)
 
static Ssiz_t GetInitialCapacity ()
 
static Ssiz_t GetMaxWaste ()
 
static Ssiz_t GetResizeIncrement ()
 
static UInt_t Hash (const void *txt, Int_t ntxt)
 
static Ssiz_t InitialCapacity (Ssiz_t ic=15)
 
static TString Itoa (Int_t value, Int_t base)
 
static TString LLtoa (Long64_t value, Int_t base)
 
static Ssiz_t MaxWaste (Ssiz_t mw=15)
 
static TStringReadString (TBuffer &b, const TClass *clReq)
 
static Ssiz_t ResizeIncrement (Ssiz_t ri=16)
 
static TString UItoa (UInt_t value, Int_t base)
 
static TString ULLtoa (ULong64_t value, Int_t base)
 
static void WriteString (TBuffer &b, const TString *a)
 

Protected Attributes

Bool_t fEndList
 used by Next() & End() to iterate over list More...
 
Int_t fIterIndex
 used by Next() to iterate over list More...
 
std::unique_ptr< TObjArraykObjArr
 used by Next() to iterate over list More...
 
- Protected Attributes inherited from TString
Rep_t fRep
 
 kAlignment
 

Additional Inherited Members

- Public Types inherited from TString
enum  ECaseCompare
 
enum  EStripType
 
- Public Attributes inherited from TString
 kBoth
 
 kExact
 
 kIgnoreCase
 
 kLeading
 
 kTrailing
 
- Static Public Attributes inherited from TString
static const Ssiz_t kNPOS
 
- Protected Member Functions inherited from TString
 TString (const char *a1, Ssiz_t n1, const char *a2, Ssiz_t n2)
 
void AssertElement (Ssiz_t nc) const
 
void Clobber (Ssiz_t nc)
 
void InitChar (char c)
 
- Static Protected Member Functions inherited from TString
static Ssiz_t AdjustCapacity (Ssiz_t oldCap, Ssiz_t newCap)
 
static Ssiz_t Align (Ssiz_t s)
 
static Ssiz_t Recommend (Ssiz_t s)
 

#include <KVString.h>

Inheritance diagram for KVString:
Inheritance graph
[legend]

Constructor & Destructor Documentation

◆ KVString() [1/5]

KVString::KVString ( )
inline

Definition at line 82 of file KVString.h.

◆ KVString() [2/5]

KVString::KVString ( const Char_t s)
inline

Definition at line 85 of file KVString.h.

◆ KVString() [3/5]

KVString::KVString ( const TString s)
inline

Definition at line 88 of file KVString.h.

◆ KVString() [4/5]

KVString::KVString ( const KVString s)
inline

Definition at line 91 of file KVString.h.

◆ KVString() [5/5]

KVString::KVString ( Double_t  value,
Double_t  error 
)

Definition at line 1466 of file KVString.cpp.

◆ ~ KVString()

virtual KVString::~ KVString ( )
inlinevirtual

Definition at line 96 of file KVString.h.

Member Function Documentation

◆ BaseConvert()

KVString KVString::BaseConvert ( const KVString s_in,
Int_t  base_in,
Int_t  base_out 
)
static

Converts string from base base_in to base base_out. Supported bases are 2-36. At most 64 bit data can be converted.

Definition at line 1192 of file KVString.cpp.

◆ Begin()

void KVString::Begin ( TString  delim) const

Begin(), Next() and End() can be used to loop over items in a string separated by the delimiter character given as argument to Begin().

Example:

KVString str("First | Second | Third");
str.Begin("|");
while( !str.End() ){
cout << str.Next().Data() << endl;
}

This will give the following output:

Second
Third
Warning
If the delimiter character is not contained in the string, calling Next() will return the entire contents of the string, after which End() will return kTRUE. This allows to parse strings containing variable numbers of parameters separated by a delimiter which is only used with 2 or more parameters, i.e.:
"par1|par2|par3" -> "par1" "par2" "par3"
"par1" -> "par1"

Definition at line 565 of file KVString.cpp.

◆ Capitalize()

void KVString::Capitalize ( )

Change first character of string from lower to upper case.

Definition at line 1454 of file KVString.cpp.

◆ End()

Bool_t KVString::End ( void  ) const

Begin(), Next() and End() can be used to loop over items in a string separated by the delimiter character given as argument to Begin().

Example:

KVString str("First | Second | Third");
str.Begin("|");
while( !str.End() ){
cout << str.Next().Data() << endl;
}

This will give the following output:

Second
Third

Definition at line 634 of file KVString.cpp.

◆ FindCommonCharacters()

KVString & KVString::FindCommonCharacters ( const TCollection list,
const char  bug = '*' 
)

list is a collection of objects with names this method generates a string containing all characters which appear in every name in the list, the others are replaced by the 'bug' character.

example: list contains a set of TNamed with names: run_0001.root run_0002.root ... run_0099.root

then toto.FindCommonCharacters(list) will produce toto="run_00*.root"

Definition at line 1307 of file KVString.cpp.

◆ FindCommonTitleCharacters()

KVString & KVString::FindCommonTitleCharacters ( const TCollection list,
const char  bug = '*' 
)

list is a collection of objects with titles this method generates a string containing all characters which appear in every title in the list, the others are replaced by the 'bug' character.

example: list contains a set of TNamed with titles: run_0001.root run_0002.root ... run_0099.root

then toto.FindCommonCharacters(list) will produce toto="run_00*.root"

Definition at line 1377 of file KVString.cpp.

◆ GetNValues()

Int_t KVString::GetNValues ( TString  delim) const

Count the number of substrings in this string separated by the given character(s) e.g. given a string "one | two | three", GetNValues("|") returns 3 Note that if the 'delim' character is not contained in the string, GetNValues() will return 1 (not 0) - see Begin().

Definition at line 886 of file KVString.cpp.

◆ Itoa()

KVString KVString::Itoa ( Int_t  value,
Int_t  base 
)
static

Converts an Int_t to a KVString with respect to the base specified (2-36). Thus it is an enhanced version of sprintf (adapted from versions 0.4 of http://www.jb.man.ac.uk/~slowe/cpp/itoa.html). Usage: the following statement produce the same output, namely "1111" std::cout << KVString::Itoa(15,2) ; std::cout << KVString::Itoa(0xF,2) ; /// 0x prefix to handle hex std::cout << KVString::Itoa(017,2) ; /// 0 prefix to handle oct In case of error returns the "!" string.

Definition at line 1038 of file KVString.cpp.

◆ LLtoa()

KVString KVString::LLtoa ( Long64_t  value,
Int_t  base 
)
static

Converts a Long64_t to a KVString with respect to the base specified (2-36). Thus it is an enhanced version of sprintf (adapted from versions 0.4 of http://www.jb.man.ac.uk/~slowe/cpp/itoa.html). In case of error returns the "!" string.

Definition at line 1118 of file KVString.cpp.

◆ Match()

Bool_t KVString::Match ( TString  pattern)
virtual

Check if pattern fit the considered string As in ls shell command the * symbol represents the non discriminant part of the pattern if no * is present in the pattern, the result correspond to TString::Contains method Example KVString st(file_R45.dat); st.Match("*") -> kTRUE st.Match("file") ->kTRUE st.Match("*file*R*") ->kTRUE etc ....

Definition at line 494 of file KVString.cpp.

◆ Next()

KVString KVString::Next ( Bool_t  strip_whitespace = kFALSE) const

Begin(), Next() and End() can be used to loop over items in a string separated by the delimiter character given as argument to Begin().

Parameters
[in]strip_whitespaceif kTRUE (default is kFALSE), any leading or trailing whitespace is removed from each item
Returns
next item in string separated by delimiter(s) given to Begin()

Example:

KVString str("First | Second | Third");
str.Begin("|");
while( !str.End() ){
cout << str.Next(kTRUE).Data() << endl;
}

This will give the following output:

Second
Third

whereas if Next() is used (i.e. strip_whitespace=kFALSE), this gives:

Second
Third

Definition at line 695 of file KVString.cpp.

◆ operator=() [1/3]

KVString & KVString::operator= ( const char *  s)
inline

Definition at line 182 of file KVString.h.

◆ operator=() [2/3]

KVString & KVString::operator= ( const KVString s)
inline

Definition at line 168 of file KVString.h.

◆ operator=() [3/3]

KVString & KVString::operator= ( const TString s)
inline

Definition at line 176 of file KVString.h.

◆ RandomLetterSequence()

void KVString::RandomLetterSequence ( Int_t  length)

Generate a random sequence of upper- and lower-case letters of given length

Definition at line 1436 of file KVString.cpp.

◆ RBegin()

void KVString::RBegin ( TString  delim) const

RBegin(), RNext() and End() can be used to loop BACKWARDS over items in a string separated by the delimiter character given as argument to RBegin().

Example: KVString str("First | Second | Third"); str.RBegin("|"); while( !str.End() ){ cout << str.RNext().Data() << endl; }

This will give the following output:

Third Second First

WARNING: If the delimiter character is not contained in the string, calling RNext() will return the entire contents of the string, after which End() will return kTRUE. This allows to parse strings containing variable numbers of parameters separated by a delimiter which is only used with 2 or more parameters, i.e.:

"par1|par2|par3" -> "par3" "par2" "par1" "par1" -> "par1"

Definition at line 768 of file KVString.cpp.

◆ RemoveAllExtraWhiteSpace()

void KVString::RemoveAllExtraWhiteSpace ( )

Remove any superfluous whitespace (or tabs or newlines) from this string (modifies string) i.e. transform " Mary Had\tA Little \n Laaaaaaaaaaaaaaaaaamb" into "Mary Had A Little Lamb"

Definition at line 1253 of file KVString.cpp.

◆ RNext()

KVString KVString::RNext ( Bool_t  strip_whitespace = kFALSE) const

RBegin(), RNext() and End() can be used to loop BACKWARDS over items in a string separated by the delimiter character given as argument to RBegin(). If strip_whitespace=kTRUE (default is kFALSE), any leading or trailing whitespace is removed from each item.

Example: KVString str("First | Second | Third"); str.RBegin("|"); while( !str.End() ){ cout << str.RNext(kTRUE).Data() << endl; }

This will give the following output:

Third Second First

whereas if RNext() is used (i.e. strip_whitespace=kFALSE), this gives:

Third Second First

Definition at line 841 of file KVString.cpp.

◆ Sscanf()

Int_t KVString::Sscanf ( const Char_t fmt,
  ... 
)
virtual

A more strict implementation than the standard 'sscanf' We require that any characters in the format string which are not format descriptors ("%d" etc.) be identical to the characters in this KVString

i.e. for a string "file6.root", sscanf("file6.root", "file%d.root", &some_integer) returns 1 but so does sscanf("file6.root", "file%danything_you_want_here_i_dont_care", &some_integer).

Use this method when you ONLY want "file%d.root" to match "file6.root"

Returns number of fields read from string

HANDLED FORMAT DESCRIPTORS

d - simple integer descriptor %3d - simple integer descriptor with length - only integers of correct length accepted (leading characters may be white space, i.e. ' 4' for 4 written with '%3d') %03d - simple integer descriptor with length + zero padding - only integers of correct length accepted (leading characters may be zeroes, i.e. '004' for 4 written with '%03d') %* - just garbage, no argument required, it is not read. we ignore the rest of the string and the rest of the format. this is not counted as a field to be read. i.e. Sscanf("%*") gives 0 for any string, not because it doesn't match, but because there is nothing to read.

Definition at line 320 of file KVString.cpp.

◆ StripAllExtraWhiteSpace()

KVString KVString::StripAllExtraWhiteSpace ( ) const

Remove any superfluous whitespace (or tabs or newlines) from string (does not modify string) i.e. transform " Mary Had\tA Little \n Laaaaaaaaaaaaaaaaaamb" into "Mary Had A Little Lamb"

Definition at line 1275 of file KVString.cpp.

◆ Substitute()

KVString & KVString::Substitute ( const Char_t  c1,
const Char_t  c2 
)
virtual

Replace every occurence of 'c1' with 'c2'.

Definition at line 275 of file KVString.cpp.

◆ UItoa()

KVString KVString::UItoa ( UInt_t  value,
Int_t  base 
)
static

Converts a UInt_t (twice the range of an Int_t) to a KVString with respect to the base specified (2-36). Thus it is an enhanced version of sprintf (adapted from versions 0.4 of http://www.jb.man.ac.uk/~slowe/cpp/itoa.html). In case of error returns the "!" string.

Definition at line 1081 of file KVString.cpp.

◆ ULLtoa()

KVString KVString::ULLtoa ( ULong64_t  value,
Int_t  base 
)
static

Converts a ULong64_t (twice the range of an Long64_t) to a KVString with respect to the base specified (2-36). Thus it is an enhanced version of sprintf (adapted from versions 0.4 of http://www.jb.man.ac.uk/~slowe/cpp/itoa.html). In case of error returns the "!" string.

Definition at line 1157 of file KVString.cpp.

◆ Vectorize()

std::vector< KVString > KVString::Vectorize ( TString  delim,
Bool_t  strip_whitespace = kFALSE 
)

Split string into components according to delimiter 'delim' See Begin()/Next()/End()

Definition at line 909 of file KVString.cpp.

Member Data Documentation

◆ fEndList

Bool_t KVString::fEndList
mutableprotected

used by Next() & End() to iterate over list

Definition at line 78 of file KVString.h.

◆ fIterIndex

Int_t KVString::fIterIndex
mutableprotected

used by Next() to iterate over list

Definition at line 77 of file KVString.h.

◆ kObjArr

std::unique_ptr<TObjArray> KVString::kObjArr
mutableprotected

used by Next() to iterate over list

Definition at line 76 of file KVString.h.


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