38 std::transform(begin(), end(), begin(),[](
unsigned char _c){
return std::tolower(_c); });
44 std::transform(begin(), end(), begin(),[](
unsigned char _c){
return std::toupper(_c); });
60 const char* cp = data();
61 size_t len = length();
62 if (len == 0)
return false;
64 for (
size_t i = 0; i < len; ++i) {
65 if (cp[i] !=
' ' && !isdigit(cp[i]))
return false;
66 if (cp[i] ==
' ') b++;
67 if (isdigit(cp[i])) d++;
95 int i_dot, i_e, i_plus, i_minus, i_comma;
97 i_dot = tmp.
index(
".");
98 if (i_dot > -1) tmp.replace(i_dot, 1,
" ", 1);
99 i_comma = tmp.
index(
",");
100 if (i_comma > -1) tmp.replace(i_comma, 1,
" ", 1);
101 i_e = tmp.
index(
"e");
103 tmp.replace(i_e, 1,
" ", 1);
106 i_e = tmp.
index(
"E");
107 if (i_e > -1) tmp.replace(i_e, 1,
" ", 1);
109 i_plus = tmp.
index(
"+");
110 if (i_plus > -1) tmp.replace(i_plus, 1,
" ", 1);
111 i_minus = tmp.
index(
"-");
112 if (i_minus > -1) tmp.replace(i_minus, 1,
" ", 1);
154 int end =
index(
" ");
157 return std::atoi(data());
161 return std::atoi(tmp.data());
171 int comma =
index(
",");
172 int end =
index(
" ");
174 if (comma == -1 && end == -1)
175 return std::atof(data());
179 tmp.replace(comma, 1,
".");
183 return std::atof(tmp.data());
187 return std::atof(tmp.data());
203 return tmp_copy.find(test,_pos);
214 return strcmp(_s, data()) == 0;
215 return strcasecmp(_s, data()) == 0;
220 if (!_s)
return true;
222 size_t l = strlen(_s);
223 if (l > length())
return false;
224 const char *s2 = data() + length() - l;
227 return strcmp(_s, s2) == 0;
228 return strcasecmp(_s, s2) == 0;
233 std::vector<tkstring> tokens;
234 std::list<int> splitIndex;
236 size_t i, start, nrDiff = 0;
238 for (i = 0; i < _delim.length(); i++) {
240 while (start < length()) {
241 size_t pos = find(_delim.at(i), start);
242 if (pos == npos)
break;
243 splitIndex.push_back(pos);
246 if (start > 0) nrDiff++;
248 splitIndex.push_back(length());
254 std::list<int>::const_iterator it;
256 for (it = splitIndex.begin(); it != splitIndex.end(); ++it) {
258 for (it = splitIndex.begin(); it != (std::list<int>::const_iterator) splitIndex.end(); ++it) {
261 if (stop - 1 >= start + 1) {
263 if(tok.length()) tokens.push_back(tok);
272 std::vector<tkstring> tokens;
273 size_t start = 0, pos = 0;
276 while ((pos = find(_delim, start)) != npos) {
278 if (token.length()) {
279 tokens.push_back(token);
282 start = pos + _delim.length();
287 if (token.length()) {
288 tokens.push_back(token);
296 if (_s1 && _ls1 > 0) {
298 while ((pos = find(_s1,pos,_ls1)) != npos) {
299 replace(pos, _ls1, _s2, _ls2);
308 std::size_t found = find_last_of(_s1);
316 std::size_t found = find_last_of(_s1);
325 static size_t buffer_size;
328 va_start(argptr, _format);
329 size_t length = vsnprintf(buffer, buffer_size, _format, argptr);
332 if (length + 1 > buffer_size) {
333 buffer_size = length + 1;
334 char *tmp =
static_cast<char*
>(realloc(buffer, buffer_size));
335 if(tmp) buffer = tmp;
337 va_start(argptr, _format);
338 vsnprintf(buffer, buffer_size, _format, argptr);
355 for(
size_t i=0 ; i<length() ; i++) {
356 if ((*
this)[i] >=
'a' && (*
this)[i] <=
'z') {
357 (*this)[i] -= (
'a' -
'A');
368 const char *cp = data();
369 size_t len = length();
371 for (
size_t i = 0; i < len; ++i)
382 const char *cp = data();
383 size_t len = length();
385 for (
size_t i = 0; i < len; ++i)
399 const char *cp = data();
400 size_t len = length();
401 if (len == 0)
return false;
402 for (
size_t i = 0; i < len; ++i)
411 static size_t buffer_size;
414 va_start(argptr, _format);
415 size_t length = vsnprintf(buffer, buffer_size, _format, argptr);
418 if (length + 1 > buffer_size) {
419 buffer_size = length + 1;
420 char *tmp =
static_cast<char*
>(realloc(buffer, buffer_size));
421 if(tmp) buffer = tmp;
423 va_start(argptr, _format);
424 vsnprintf(buffer, buffer_size, _format, argptr);
439 tkstring sy_dec, sy_exp, sey_dec, sey_exp;
440 double y_dec, ey_dec;
444 std::vector<tkstring> loa_y = sy.
tokenize(
"e");
445 sy_dec = loa_y.front();
446 sy_exp = loa_y.back();
448 y_dec = sy_dec.
atof();
449 y_exp = sy_exp.
atoi();
452 std::vector<tkstring> loa_ey = sey.
tokenize(
"e");
454 sey_dec = loa_ey.front();
455 sey_exp = loa_ey.back();
457 ey_dec = sey_dec.
atof();
458 ey_exp = sey_exp.
atoi();
460 double err = ey_dec * pow(10., ey_exp - y_exp);
466 if (y_exp == ey_exp) s =
Form(
"%1.2g.0(%g.0).10$^{%d}$", y_dec, ey_dec, y_exp);
467 else s =
Form(
"%1.3g.0(%g.0).10$^{%d}$", y_dec, err, y_exp);
469 if (y_exp == ey_exp) s =
Form(
"%1.2g.0(%g0).10$^{%d}$", y_dec, ey_dec, y_exp);
470 else s =
Form(
"%1.3g.0(%g0).10$^{%d}$", y_dec, err, y_exp);
472 if (y_exp == ey_exp) s =
Form(
"%1.2g.0(%g).10$^{%d}$", y_dec, ey_dec, y_exp);
473 else s =
Form(
"%1.3g.0(%g).10$^{%d}$", y_dec, err, y_exp);
475 }
else if (
Form(
"%1.3g", y_dec) ==
Form(
"%1.2g", y_dec) &&
Form(
"%1.2g", y_dec).
contains(
".") && err < 1) {
477 if (y_exp == ey_exp) s =
Form(
"%1.2g0(%g.0).10$^{%d}$", y_dec, ey_dec, y_exp);
478 else s =
Form(
"%1.3g0(%g.0).10$^{%d}$", y_dec, err, y_exp);
480 if (y_exp == ey_exp) s =
Form(
"%1.2g0(%g0).10$^{%d}$", y_dec, ey_dec, y_exp);
481 else s =
Form(
"%1.3g0(%g0).10$^{%d}$", y_dec, err, y_exp);
483 if (y_exp == ey_exp) s =
Form(
"%1.2g0(%g).10$^{%d}$", y_dec, ey_dec, y_exp);
484 else s =
Form(
"%1.3g0(%g).10$^{%d}$", y_dec, err, y_exp);
487 if (y_exp == ey_exp) s =
Form(
"%1.2g(%g.0).10$^{%d}$", y_dec, ey_dec, y_exp);
488 else s =
Form(
"%1.3g(%g.0).10$^{%d}$", y_dec, err, y_exp);
490 if (y_exp == ey_exp) s =
Form(
"%1.2g(%g0).10$^{%d}$", y_dec, ey_dec, y_exp);
491 else s =
Form(
"%1.3g(%g0).10$^{%d}$", y_dec, err, y_exp);
493 if (y_exp == ey_exp) s =
Form(
"%1.2g(%g).10$^{%d}$", y_dec, ey_dec, y_exp);
494 else s =
Form(
"%1.3g(%g).10$^{%d}$", y_dec, err, y_exp);;
512 for(
const auto &s: tmp.
tokenize(
" \n\t")) {
513 if (tmp2.length()) tmp2 +=
" ";
529 while ((pos = find(_st,pos)) != npos) {
546 for(
const auto &s: tmp.
tokenize(
" \n\t")) {
547 if (tmp2.length()) tmp2 +=
" ";
571 if (pat ==
"*")
return true;
573 std::vector<tkstring> tok = pat.
tokenize(
"*");
574 int n_tok = tok.size();
584 int idx = 0, num = 0;
585 for (
int ii = 0; ii < n_tok; ii += 1) {
586 idx =
index(tok.at(ii), idx);
592 return (num == n_tok);
602 if(_skip_white) getline(_strm >> std::ws, *
this);
603 else getline(_strm, *
this);
610 if(
error.is_empty())
return -1.;
628 double precision = 1.0;
int expo;
size_t l1,l2;
633 if ( l1 == std::string::npos ) {
634 if ( l2 == std::string::npos )
639 precision = pow(10.,expo);
642 if ( l2 == std::string::npos ) {
643 expo = - (st.size() - l1 - 1);
644 precision = pow(10.0,expo);
649 expo = - (l2 - l1 - 1) + expo;
650 precision = pow(10.0,expo);
653 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)