TkN 2.1
Toolkit for Nuclei
tkstring Class Reference

std::string with usefull tricks from TString (ROOT) and KVString (KaliVeda) and more... More...

Detailed Description

std::string with usefull tricks from TString (ROOT) and KVString (KaliVeda) and more...

Definition at line 53 of file tkstring.h.

Inheritance diagram for tkstring:

#include <tkstring.h>

Public Types

enum  ECaseCompare { kExact , kIgnoreCase }
 

Public Member Functions

 tkstring ()
 
 tkstring (char _c)
 
 tkstring (const char *_c)
 
 tkstring (const std::string &_s)
 
 tkstring (const unsigned char *_c)
 
 tkstring (double _value, double _error)
 
virtual ~tkstring ()
 
tkstringappend (const tkstring &_st)
 
double atof () const
 Converts a string to double value. More...
 
int atoi () const
 Converts a string to integer value. More...
 
int64_t atoll () const
 Converts a string to long integer value. More...
 
bool begins_with (const char *_s, ECaseCompare _cmp=kExact) const
 
bool begins_with (const tkstring &_pat, ECaseCompare _cmp=kExact) const
 
tkstringcapitalize ()
 Change first letter of string from lower to upper case. More...
 
bool contains (const char *_pat, ECaseCompare _cmp=kExact) const
 
bool contains (const tkstring &_pat, ECaseCompare _cmp=kExact) const
 
tkstring copy () const
 Returns a copy of this string. More...
 
int count_string (const tkstring &_st) const
 
bool ends_with (const char *_s, ECaseCompare _cmp=kExact) const
 
bool ends_with (const tkstring &_pat, ECaseCompare _cmp=kExact) const
 
bool equal_to (const char *_s, ECaseCompare _cmp=kExact) const
 Returns true if the string and _s are identical. More...
 
bool equal_to (const tkstring &_pat, ECaseCompare _cmp=kExact) const
 
tkstring extract_alpha ()
 Returns a tkstring composed only of the alphabetic letters of the original tkstring. More...
 
tkstring get_last_occurence (const char *_s1)
 
size_t index (const char *_s, size_t _pos=0, ECaseCompare _cmp=kExact) const
 Returns the index of the substring _s. More...
 
size_t index (const tkstring &_pat, size_t _pos=0, ECaseCompare _cmp=kExact) const
 Returns the index of the substring _pat. More...
 
bool is_alpha () const
 Checks whether tkstring is only composed of alphabetic letters. More...
 
bool is_digit () const
 Checks if all characters in string are digits (0-9) or whitespaces. More...
 
bool is_empty () const
 
bool is_float () const
 Checks if string contains a floating point or integer number. More...
 
bool match (const char *_pattern) const
 
bool match (const tkstring &_pattern) const
 
tkstringprepend (const tkstring &_st)
 
std::istream & read_line (std::istream &_strm, bool _skip_white=true)
 tkstring::read_line More...
 
tkstringremove_all (const char *_s1)
 
tkstringremove_all (const tkstring &_s1)
 
tkstringremove_all_extra_white_space ()
 
tkstring remove_alpha ()
 Returns a tkstring composed only of the non alphabetic letters of the original tkstring. More...
 
tkstring remove_last_occurence (const char *_s1)
 
tkstringreplace_all (const char *_s1, const char *_s2)
 
tkstringreplace_all (const char *_s1, const tkstring &_s2)
 
tkstringreplace_all (const char *_s1, size_t _ls1, const char *_s2, size_t _ls2)
 
tkstringreplace_all (const tkstring &_s1, const char *_s2)
 
tkstringreplace_all (const tkstring &_s1, const tkstring &_s2)
 
tkstring strip_all_extra_white_space () const
 
tkstring substr (size_type __pos=0, size_type __n=npos) const
 Inlines. More...
 
tkstringto_lower ()
 Change all letters to lower case. More...
 
tkstringto_upper ()
 Change all letters to upper case. More...
 
std::vector< tkstringtokenize (const tkstring &_delim=" ") const
 Create a vector of string separated by at least one delimiter. More...
 
std::vector< tkstringtokenize_from_string (const tkstring &_delim) const
 Create a vector of string separated by a full string as delimiter. More...
 

Static Public Member Functions

static tkstring Form (const char *_format,...)
 
static const char * form (const char *_format,...)
 
static double get_absolute_error (tkstring val, tkstring error)
 Get absolute uncertainty from value and error strings (1.27 4 -> 0.04), returns -1 in case of empty error string. More...
 
static double get_precision (tkstring _st)
 Extract the precision for a given ENSDF data. More...
 

Member Enumeration Documentation

◆ ECaseCompare

Enumerator
kExact 
kIgnoreCase 

Definition at line 57 of file tkstring.h.

Constructor & Destructor Documentation

◆ tkstring() [1/6]

tkstring ( )
inline

Definition at line 60 of file tkstring.h.

◆ tkstring() [2/6]

tkstring ( const char *  _c)
inline

Definition at line 61 of file tkstring.h.

◆ tkstring() [3/6]

tkstring ( const unsigned char *  _c)
inline

Definition at line 62 of file tkstring.h.

◆ tkstring() [4/6]

tkstring ( const std::string &  _s)
inline

Definition at line 63 of file tkstring.h.

◆ tkstring() [5/6]

tkstring ( double  _value,
double  _error 
)

Definition at line 454 of file tkstring.cpp.

◆ tkstring() [6/6]

tkstring ( char  _c)
inline

Definition at line 66 of file tkstring.h.

◆ ~tkstring()

virtual ~tkstring ( )
inlinevirtual

Definition at line 68 of file tkstring.h.

Member Function Documentation

◆ append()

tkstring & append ( const tkstring _st)
inline

Definition at line 227 of file tkstring.h.

◆ atof()

double atof ( ) const

Converts a string to double value.

Basically a copy of KVString::Atof() from KaliVeda

Definition at line 191 of file tkstring.cpp.

◆ atoi()

int atoi ( ) const

Converts a string to integer value.

Basically a copy of KVString::Atoi() from KaliVeda

Definition at line 175 of file tkstring.cpp.

◆ atoll()

int64_t atoll ( ) const
inline

Converts a string to long integer value.

Definition at line 89 of file tkstring.h.

◆ begins_with() [1/2]

bool begins_with ( const char *  _s,
ECaseCompare  _cmp = kExact 
) const
inline

Definition at line 185 of file tkstring.h.

◆ begins_with() [2/2]

bool begins_with ( const tkstring _pat,
ECaseCompare  _cmp = kExact 
) const
inline

Definition at line 188 of file tkstring.h.

◆ capitalize()

tkstring & capitalize ( )

Change first letter of string from lower to upper case.

Definition at line 376 of file tkstring.cpp.

◆ contains() [1/2]

bool contains ( const char *  _pat,
ECaseCompare  _cmp = kExact 
) const
inline

Definition at line 197 of file tkstring.h.

◆ contains() [2/2]

bool contains ( const tkstring _pat,
ECaseCompare  _cmp = kExact 
) const
inline

Definition at line 194 of file tkstring.h.

◆ copy()

tkstring copy ( ) const

Returns a copy of this string.

Definition at line 370 of file tkstring.cpp.

◆ count_string()

int count_string ( const tkstring _st) const

Definition at line 547 of file tkstring.cpp.

◆ ends_with() [1/2]

bool ends_with ( const char *  _s,
ECaseCompare  _cmp = kExact 
) const

Definition at line 241 of file tkstring.cpp.

◆ ends_with() [2/2]

bool ends_with ( const tkstring _pat,
ECaseCompare  _cmp = kExact 
) const
inline

Definition at line 191 of file tkstring.h.

◆ equal_to() [1/2]

bool equal_to ( const char *  _s,
ECaseCompare  _cmp = kExact 
) const

Returns true if the string and _s are identical.

Parameters
_sstring to compare with
_cmpkExact or kIgnoreCase

Definition at line 234 of file tkstring.cpp.

◆ equal_to() [2/2]

bool equal_to ( const tkstring _pat,
ECaseCompare  _cmp = kExact 
) const
inline

Definition at line 182 of file tkstring.h.

◆ extract_alpha()

tkstring extract_alpha ( )

Returns a tkstring composed only of the alphabetic letters of the original tkstring.

Definition at line 387 of file tkstring.cpp.

◆ Form()

tkstring Form ( const char *  _format,
  ... 
)
static

Definition at line 345 of file tkstring.cpp.

◆ form()

const char * form ( const char *  _format,
  ... 
)
static

Definition at line 431 of file tkstring.cpp.

◆ get_absolute_error()

double get_absolute_error ( tkstring  val,
tkstring  error 
)
static

Get absolute uncertainty from value and error strings (1.27 4 -> 0.04), returns -1 in case of empty error string.

Definition at line 631 of file tkstring.cpp.

◆ get_last_occurence()

tkstring get_last_occurence ( const char *  _s1)

Definition at line 329 of file tkstring.cpp.

◆ get_precision()

double get_precision ( tkstring  st)
static

Extract the precision for a given ENSDF data.

Parameters
ststring containing an ENSDF formated data

'The standard numeric uncertainty denotes an uncertainty in the last significant figures'.

For example:

  • NR=0.873 DNR=11 means 0.873[+/-]0.011
  • QP=2.3E6 DQP=10 means (2.3[+/-]1.0)E6

Given the quantity (NR or QP ...) as a string, this method returns the coefficient that must multiply the uncertainty field to get the absolute uncertainty.

Definition at line 649 of file tkstring.cpp.

◆ index() [1/2]

size_t index ( const char *  _s,
size_t  _pos = 0,
ECaseCompare  _cmp = kExact 
) const

Returns the index of the substring _s.

Parameters
_ssubstring to find
_posoccurence of this substring
_cmpkExact or kIgnoreCase

Definition at line 218 of file tkstring.cpp.

◆ index() [2/2]

size_t index ( const tkstring _pat,
size_t  _pos = 0,
ECaseCompare  _cmp = kExact 
) const
inline

Returns the index of the substring _pat.

Definition at line 200 of file tkstring.h.

◆ is_alpha()

bool is_alpha ( ) const

Checks whether tkstring is only composed of alphabetic letters.

Returns kTRUE if string contains only alphabetic letters

Definition at line 420 of file tkstring.cpp.

◆ is_digit()

bool is_digit ( ) const

Checks if all characters in string are digits (0-9) or whitespaces.

Returns true if all characters in string are digits (0-9) or whitespaces, i.e. "123456" and "123 456" are both valid integer strings.

Returns false in case string length is 0 or string contains other characters or only whitespace.

Definition at line 81 of file tkstring.cpp.

◆ is_empty()

bool is_empty ( ) const
inline

Definition at line 163 of file tkstring.h.

◆ is_float()

bool is_float ( ) const

Checks if string contains a floating point or integer number.

Returns kTRUE if string contains a floating point or integer number.

Examples of valid formats are:

  • 64320
  • 64 320
  • 6 4 3 2 0
  • 6.4320 6,4320
  • 6.43e20 6.43E20 6,43e20
  • 6.43e-20 6.43E-20 6,43e-20

Definition at line 110 of file tkstring.cpp.

◆ match() [1/2]

bool match ( const char *  _pattern) const

Definition at line 579 of file tkstring.cpp.

◆ match() [2/2]

bool match ( const tkstring _pattern) const
inline

Definition at line 221 of file tkstring.h.

◆ prepend()

tkstring & prepend ( const tkstring _st)
inline

Definition at line 224 of file tkstring.h.

◆ read_line()

std::istream & read_line ( std::istream &  _strm,
bool  _skip_white = true 
)

tkstring::read_line

Parameters
_strm
_skip_white
Returns

Definition at line 623 of file tkstring.cpp.

◆ remove_all() [1/2]

tkstring & remove_all ( const char *  _s1)
inline

Definition at line 218 of file tkstring.h.

◆ remove_all() [2/2]

tkstring & remove_all ( const tkstring _s1)
inline

Definition at line 215 of file tkstring.h.

◆ remove_all_extra_white_space()

tkstring & remove_all_extra_white_space ( )

Definition at line 526 of file tkstring.cpp.

◆ remove_alpha()

tkstring remove_alpha ( )

Returns a tkstring composed only of the non alphabetic letters of the original tkstring.

Definition at line 401 of file tkstring.cpp.

◆ remove_last_occurence()

tkstring remove_last_occurence ( const char *  _s1)

Definition at line 337 of file tkstring.cpp.

◆ replace_all() [1/5]

tkstring & replace_all ( const char *  _s1,
const char *  _s2 
)
inline

Definition at line 212 of file tkstring.h.

◆ replace_all() [2/5]

tkstring & replace_all ( const char *  _s1,
const tkstring _s2 
)
inline

Definition at line 209 of file tkstring.h.

◆ replace_all() [3/5]

tkstring & replace_all ( const char *  _s1,
size_t  _ls1,
const char *  _s2,
size_t  _ls2 
)

Definition at line 317 of file tkstring.cpp.

◆ replace_all() [4/5]

tkstring & replace_all ( const tkstring _s1,
const char *  _s2 
)
inline

Definition at line 206 of file tkstring.h.

◆ replace_all() [5/5]

tkstring & replace_all ( const tkstring _s1,
const tkstring _s2 
)
inline

Definition at line 203 of file tkstring.h.

◆ strip_all_extra_white_space()

tkstring strip_all_extra_white_space ( ) const

Definition at line 560 of file tkstring.cpp.

◆ substr()

tkstring substr ( size_type  __pos = 0,
size_type  __n = npos 
) const
inline

Inlines.

Definition at line 179 of file tkstring.h.

◆ to_lower()

tkstring & to_lower ( )

Change all letters to lower case.

Definition at line 59 of file tkstring.cpp.

◆ to_upper()

tkstring & to_upper ( )

Change all letters to upper case.

Definition at line 65 of file tkstring.cpp.

◆ tokenize()

std::vector< tkstring > tokenize ( const tkstring _delim = " ") const

Create a vector of string separated by at least one delimiter.

Definition at line 254 of file tkstring.cpp.

◆ tokenize_from_string()

std::vector< tkstring > tokenize_from_string ( const tkstring _delim) const

Create a vector of string separated by a full string as delimiter.

Definition at line 294 of file tkstring.cpp.


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