24#include "tkn_config.h"
40 tkstring(
const char *_c) : std::string(_c ? _c :
"") {}
41 tkstring(
const unsigned char *_c) : std::string(_c ? reinterpret_cast<const char *>(_c) :
"") {}
42 tkstring(
const std::string &_s) : std::string(_s) {}
44 tkstring(
double _value,
double _error);
68 int64_t
atoll()
const;
109 bool begins_with(
char _c)
const {
return !empty() && front() == _c; }
112 bool ends_with(
char _c)
const {
return !empty() && back() == _c; }
116 bool contains(
char _c)
const {
return find(_c) != npos; }
134 static const char*
form(
const char * _format, ...);
139 std::istream &
read_line(std::istream &_strm,
bool _skip_white =
true);
141 bool match(
const char *_pattern)
const;
146 return empty() || find_first_not_of(
" \n\t") == npos;
161{
tkstring tmp = std::string::substr(__pos,__n);
return tmp;}
164{
return equal_to(_pat.data(),_cmp); }
168 if (!_s)
return false;
169#if defined(__cpp_lib_starts_ends_with) && __cpp_lib_starts_ends_with >= 201711L
170 if (_cmp ==
kExact)
return std::string::starts_with(_s);
172 return index(_s, 0, _cmp) == 0;
182{
return contains(_pat.data(), _cmp); }
186 if (!_s)
return false;
187#if defined(__cpp_lib_string_contains) && __cpp_lib_string_contains >= 202011L
188 if (_cmp ==
kExact)
return std::string::contains(_s);
190 return index(_s, 0, _cmp) != npos;
194{
return index(_pat.data(), _pos, _cmp); }
197{
return replace_all(_s1.data(), _s1.length(), _s2.data(), _s2.length()) ; }
200{
return replace_all(_s1.data(), _s1.length(), _s2, _s2 ? strlen(_s2) : 0); }
203{
return replace_all(_s1, _s1 ? strlen(_s1) : 0, _s2.data(), _s2.length()); }
206{
return replace_all(_s1, _s1 ? strlen(_s1) : 0, _s2, _s2 ? strlen(_s2) : 0); }
215{
return match(_pat.data()); }
218{ insert(0,_st);
return *
this;}
221{ std::string::append(_st);
return *
this;}
226std::string
wrap_text(
const tkstring &_text,
size_t _first_content_col,
size_t _continuation_col,
size_t _max_line_width = 80);
std::string with usefull tricks from TString (ROOT) and KVString (KaliVeda) and more....
tkstring extract_alpha()
Returns a tkstring composed only of the alphabetic letters of the original tkstring.
tkstring(const unsigned char *_c)
tkstring strip_all_extra_white_space() const
tkstring copy() const
Returns a copy of this string.
tkstring & to_lower()
Change all letters to lower case.
tkstring(const std::string &_s)
static const char * form(const char *_format,...)
bool is_float() const
Checks if string contains a floating point or integer number.
tkstring get_last_occurence(const char *_s1)
bool begins_with(char _c) const
std::vector< tkstring > tokenize(const tkstring &_delim=" ") const
Create a vector of string separated by at least one delimiter.
static tkstring Form(const char *_format,...)
bool contains(char _c) const
tkstring & remove_all(const tkstring &_s1)
bool ends_with(char _c) const
tkstring substr(size_type __pos=0, size_type __n=npos) const
Inlines.
std::vector< tkstring > tokenize_from_string(const tkstring &_delim) const
Create a vector of string separated by a full string as delimiter.
bool match(const char *_pattern) const
bool is_alpha() const
Checks whether tkstring is only composed of alphabetic letters.
std::istream & read_line(std::istream &_strm, bool _skip_white=true)
tkstring::read_line
int atoi() const
Converts a string to integer value.
bool ends_with(const char *_s, ECaseCompare _cmp=kExact) const
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 e...
bool equal_to(const char *_s, ECaseCompare _cmp=kExact) const
Returns true if the string and _s are identical.
size_t index(const char *_s, size_t _pos=0, ECaseCompare _cmp=kExact) const
Returns the index of the substring _s.
tkstring remove_alpha()
Returns a tkstring composed only of the non alphabetic letters of the original tkstring.
tkstring & remove_all_extra_white_space()
bool contains(const char *_pat, ECaseCompare _cmp=kExact) const
tkstring & prepend(const tkstring &_st)
int count_string(const tkstring &_st) const
bool begins_with(const char *_s, ECaseCompare _cmp=kExact) const
tkstring & append(const tkstring &_st)
tkstring & capitalize()
Change first letter of string from lower to upper case.
static double get_precision(tkstring _st)
Extract the precision for a given ENSDF data.
tkstring & replace_all(const tkstring &_s1, const tkstring &_s2)
bool is_digit() const
Checks if all characters in string are digits (0-9) or whitespaces.
int64_t atoll() const
Converts a string to long integer value.
tkstring remove_last_occurence(const char *_s1)
double atof() const
Converts a string to double value.
tkstring & to_upper()
Change all letters to upper case.
std::string wrap_text(const tkstring &_text, size_t _first_content_col, size_t _continuation_col, size_t _max_line_width=80)
tklog & error(tklog &log)
tkstring & append(const tkstring &_st)
tkstring & preprend(const tkstring &_st)