61 std::transform(begin(), end(), begin(),[](
unsigned char _c){
return std::tolower(_c); });
67 std::transform(begin(), end(), begin(),[](
unsigned char _c){
return std::toupper(_c); });
83 const char* cp = data();
84 size_t len = length();
85 if (len == 0)
return false;
87 for (
size_t i = 0; i < len; ++i) {
88 if (cp[i] !=
' ' && !isdigit(cp[i]))
return false;
89 if (cp[i] ==
' ') b++;
90 if (isdigit(cp[i])) d++;
118 int i_dot, i_e, i_plus, i_minus, i_comma;
120 i_dot = tmp.
index(
".");
121 if (i_dot > -1) tmp.replace(i_dot, 1,
" ", 1);
122 i_comma = tmp.
index(
",");
123 if (i_comma > -1) tmp.replace(i_comma, 1,
" ", 1);
124 i_e = tmp.
index(
"e");
126 tmp.replace(i_e, 1,
" ", 1);
129 i_e = tmp.
index(
"E");
130 if (i_e > -1) tmp.replace(i_e, 1,
" ", 1);
132 i_plus = tmp.
index(
"+");
133 if (i_plus > -1) tmp.replace(i_plus, 1,
" ", 1);
134 i_minus = tmp.
index(
"-");
135 if (i_minus > -1) tmp.replace(i_minus, 1,
" ", 1);
177 int end =
index(
" ");
180 return std::atoi(data());
184 return std::atoi(tmp.data());
194 int comma =
index(
",");
195 int end =
index(
" ");
197 if (comma == -1 && end == -1)
198 return std::atof(data());
202 tmp.replace(comma, 1,
".");
206 return std::atof(tmp.data());
210 return std::atof(tmp.data());
220 if(_cmp == ECaseCompare::kExact)
return find(_s,_pos);
226 return copy.find(test,_pos);
237 return strcmp(_s, data()) == 0;
238 return strcasecmp(_s, data()) == 0;
243 if (!_s)
return true;
245 size_t l = strlen(_s);
246 if (l > length())
return false;
247 const char *s2 = data() + length() - l;
250 return strcmp(_s, s2) == 0;
251 return strcasecmp(_s, s2) == 0;
256 std::vector<tkstring> tokens;
257 std::list<int> splitIndex;
259 size_t i, start, nrDiff = 0;
261 for (i = 0; i < _delim.length(); i++) {
263 while (start < length()) {
264 size_t pos = find(_delim.at(i), start);
265 if (pos == npos)
break;
266 splitIndex.push_back(pos);
269 if (start > 0) nrDiff++;
271 splitIndex.push_back(length());
277 std::list<int>::const_iterator it;
279 for (it = splitIndex.begin(); it != splitIndex.end(); ++it) {
281 for (it = splitIndex.begin(); it != (std::list<int>::const_iterator) splitIndex.end(); ++it) {
284 if (stop - 1 >= start + 1) {
286 if(tok.length()) tokens.push_back(tok);
295 std::vector<tkstring> tokens;
296 size_t start = 0, pos = 0;
299 while ((pos = find(_delim, start)) != npos) {
301 if (token.length()) {
302 tokens.push_back(token);
305 start = pos + _delim.length();
310 if (token.length()) {
311 tokens.push_back(token);
319 if (_s1 && _ls1 > 0) {
321 while ((
index = find(_s1,
index,_ls1)) != npos) {
322 replace(
index, _ls1, _s2, _ls2);
331 std::size_t found = find_last_of(_s1);
339 std::size_t found = find_last_of(_s1);
348 static size_t buffer_size;
351 va_start(argptr, _format);
352 size_t length = vsnprintf(buffer, buffer_size, _format, argptr);
355 if (length + 1 > buffer_size) {
356 buffer_size = length + 1;
357 char *tmp =
static_cast<char*
>(realloc(buffer, buffer_size));
358 if(tmp) buffer = tmp;
360 va_start(argptr, _format);
361 vsnprintf(buffer, buffer_size, _format, argptr);
378 for(
size_t i=0 ; i<length() ; i++) {
379 if ((*
this)[i] >=
'a' && (*this)[i] <=
'z') {
380 (*this)[i] -= (
'a' -
'A');
391 const char *cp = data();
392 size_t len = length();
394 for (
size_t i = 0; i < len; ++i)
405 const char *cp = data();
406 size_t len = length();
408 for (
size_t i = 0; i < len; ++i)
422 const char *cp = data();
423 size_t len = length();
424 if (len == 0)
return false;
425 for (
size_t i = 0; i < len; ++i)
434 static size_t buffer_size;
437 va_start(argptr, _format);
438 size_t length = vsnprintf(buffer, buffer_size, _format, argptr);
441 if (length + 1 > buffer_size) {
442 buffer_size = length + 1;
443 char *tmp =
static_cast<char*
>(realloc(buffer, buffer_size));
444 if(tmp) buffer = tmp;
446 va_start(argptr, _format);
447 vsnprintf(buffer, buffer_size, _format, argptr);
462 tkstring sy_dec, sy_exp, sey_dec, sey_exp;
463 double y_dec, ey_dec;
467 std::vector<tkstring> loa_y = sy.
tokenize(
"e");
468 sy_dec = loa_y.front();
469 sy_exp = loa_y.back();
471 y_dec = sy_dec.
atof();
472 y_exp = sy_exp.
atoi();
475 std::vector<tkstring> loa_ey = sey.
tokenize(
"e");
477 sey_dec = loa_ey.front();
478 sey_exp = loa_ey.back();
480 ey_dec = sey_dec.
atof();
481 ey_exp = sey_exp.
atoi();
483 double err = ey_dec * pow(10., ey_exp - y_exp);
489 if (y_exp == ey_exp) s =
Form(
"%1.2g.0(%g.0).10$^{%d}$", y_dec, ey_dec, y_exp);
490 else s =
Form(
"%1.3g.0(%g.0).10$^{%d}$", y_dec, err, y_exp);
492 if (y_exp == ey_exp) s =
Form(
"%1.2g.0(%g0).10$^{%d}$", y_dec, ey_dec, y_exp);
493 else s =
Form(
"%1.3g.0(%g0).10$^{%d}$", y_dec, err, y_exp);
495 if (y_exp == ey_exp) s =
Form(
"%1.2g.0(%g).10$^{%d}$", y_dec, ey_dec, y_exp);
496 else s =
Form(
"%1.3g.0(%g).10$^{%d}$", y_dec, err, y_exp);
498 }
else if (
Form(
"%1.3g", y_dec) ==
Form(
"%1.2g", y_dec) &&
Form(
"%1.2g", y_dec).
contains(
".") && err < 1) {
500 if (y_exp == ey_exp) s =
Form(
"%1.2g0(%g.0).10$^{%d}$", y_dec, ey_dec, y_exp);
501 else s =
Form(
"%1.3g0(%g.0).10$^{%d}$", y_dec, err, y_exp);
503 if (y_exp == ey_exp) s =
Form(
"%1.2g0(%g0).10$^{%d}$", y_dec, ey_dec, y_exp);
504 else s =
Form(
"%1.3g0(%g0).10$^{%d}$", y_dec, err, y_exp);
506 if (y_exp == ey_exp) s =
Form(
"%1.2g0(%g).10$^{%d}$", y_dec, ey_dec, y_exp);
507 else s =
Form(
"%1.3g0(%g).10$^{%d}$", y_dec, err, y_exp);
510 if (y_exp == ey_exp) s =
Form(
"%1.2g(%g.0).10$^{%d}$", y_dec, ey_dec, y_exp);
511 else s =
Form(
"%1.3g(%g.0).10$^{%d}$", y_dec, err, y_exp);
513 if (y_exp == ey_exp) s =
Form(
"%1.2g(%g0).10$^{%d}$", y_dec, ey_dec, y_exp);
514 else s =
Form(
"%1.3g(%g0).10$^{%d}$", y_dec, err, y_exp);
516 if (y_exp == ey_exp) s =
Form(
"%1.2g(%g).10$^{%d}$", y_dec, ey_dec, y_exp);
517 else s =
Form(
"%1.3g(%g).10$^{%d}$", y_dec, err, y_exp);;
535 for(
const auto &s: tmp.
tokenize(
" \n\t")) {
536 if (tmp2.length()) tmp2 +=
" ";
553 index += _st.length();
569 for(
const auto &s: tmp.
tokenize(
" \n\t")) {
570 if (tmp2.length()) tmp2 +=
" ";
594 if (pat ==
"*")
return true;
596 std::vector<tkstring> tok = pat.
tokenize(
"*");
597 int n_tok = tok.size();
607 int idx = 0, num = 0;
608 for (
int ii = 0; ii < n_tok; ii += 1) {
609 idx =
index(tok.at(ii), idx);
615 return (num == n_tok);
625 if(_skip_white) getline(_strm >> std::ws, *
this);
626 else getline(_strm, *
this);
633 if(
error.is_empty())
return -1.;
651 double precision = 1.0;
int expo;
size_t l1,l2;
656 if ( l1 == std::string::npos ) {
657 if ( l2 == std::string::npos )
662 precision = pow(10.,expo);
665 if ( l2 == std::string::npos ) {
666 expo = - (st.size() - l1 - 1);
667 precision = pow(10.0,expo);
672 expo = - (l2 - l1 - 1) + expo;
673 precision = pow(10.0,expo);
676 if ( precision < 0 ) precision = -1.0 * precision;
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 strip_all_extra_white_space() const
tkstring copy() const
Returns a copy of this string.
tkstring & to_lower()
Change all letters to lower case.
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)
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,...)
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
int count_string(const tkstring &_st) const
bool begins_with(const char *_s, ECaseCompare _cmp=kExact) const
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.
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.
tklog & error(tklog &log)