REST-for-Physics  v2.3
Rare Event Searches ToolKit for Physics
TRestStringHelper.cxx
1#include "TRestStringHelper.h"
2
3#include <Rtypes.h>
4#include <TApplication.h>
5#include <TSystem.h>
6#include <TTimer.h>
7
8#if ROOT_VERSION_CODE < ROOT_VERSION(6, 0, 0)
9#include <TFormula.h>
10#else
11#include <v5/TFormula.h>
12#endif
13
14using namespace std;
15
27Int_t REST_StringHelper::isAExpression(const string& in) {
28 bool symbol = false;
29
30 if (in.length() < 2) // minimum expression: 3%
31 return 0;
32
33 vector<string> funcs{"sqrt", "log", "exp", "gaus", "cos", "sin", "tan", "atan", "acos", "asin"};
34 for (const auto& item : funcs) {
35 if (in.find(item) != string::npos) {
36 symbol = true;
37 break;
38 }
39 }
40
41 if (!symbol) {
42 size_t pos = in.substr(1, in.length() - 2).find_first_of("+-*/e^%");
43 if (pos != string::npos) {
44 symbol = true;
45 }
46 }
47
48 if (!symbol) {
49 size_t pos = in.find_first_of("%");
50 if (pos == in.size() - 1) {
51 symbol = true;
52 }
53 }
54
55 if (symbol) {
56 string temp = in;
57 for (const auto& item : funcs) {
58 temp = Replace(temp, item, "0", 0);
59 }
60 if (temp.find_first_not_of("-0123456789e+*/.,)( ^%") == string::npos) {
61 if (temp.find("/") == 0 || temp.find("./") == 0 || temp.find("../") == 0)
62 return 0; // identify path
63 return 1;
64 }
65 } else {
66 return 0;
67 }
68
69 return 0;
70}
71
78string REST_StringHelper::CropWithPrecision(string in, Int_t precision) {
79 if (precision == 0) return in;
80 if (REST_StringHelper::isANumber(in) && in.find(".") != string::npos) {
81 string rootStr;
82 size_t newPrecision = precision;
83 if (in.find("e") != string::npos) {
84 rootStr = in.substr(in.find("e"), -1);
85 newPrecision = std::min((int)newPrecision, (int)in.find("e") - (int)in.find(".") - 1);
86 }
87 std::string rr = in.substr(0, in.find(".") + newPrecision + 1) + rootStr;
88 return rr;
89 }
90 return in;
91}
92
102string REST_StringHelper::ReplaceMathematicalExpressions(string buffer, Int_t precision,
103 string errorMessage) {
104 buffer = Replace(buffer, " AND ", " && ");
105 buffer = Replace(buffer, " OR ", " || ");
106
107 if (buffer.find("'") != string::npos && count(buffer.begin(), buffer.end(), '\'') % 2 == 0) {
108 size_t pos1 = buffer.find("'");
109 size_t pos2 = buffer.find("'", pos1 + 1);
110 string expr = buffer.substr(pos1 + 1, pos2 - pos1 - 1);
111
112 if (!isAExpression(expr)) return buffer;
113
114 string evalExpr = ReplaceMathematicalExpressions(expr, precision);
115 expr = "'" + expr + "'";
116 string newbuff = Replace(buffer, expr, evalExpr);
117
118 return ReplaceMathematicalExpressions(newbuff, precision, errorMessage);
119 }
120
121 // we spilt the unit part and the expresstion part
122 int pos = buffer.find_last_of("1234567890().");
123
124 string unit = buffer.substr(pos + 1, -1);
125 string temp = buffer.substr(0, pos + 1);
126 string result = "";
127
128 bool erased = false;
129
130 vector<string> Expressions = Split(temp, ",");
131
132 if (Expressions.size() > 1 && Expressions[0][0] == '(' &&
133 Expressions[Expressions.size() - 1][Expressions[Expressions.size() - 1].size() - 1] == ')') {
134 Expressions[0].erase(0, 1);
135 Expressions[Expressions.size() - 1].erase(Expressions[Expressions.size() - 1].size() - 1, 1);
136 erased = true;
137 }
138
139 for (size_t i = 0; i < Expressions.size(); i++) {
140 if (!isAExpression(Expressions[i])) {
141 result += Expressions[i] + ",";
142 continue;
143 }
144 string evaluated = EvaluateExpression(Expressions[i]);
145 if (evaluated == "RESTerror") {
146 result += Expressions[i] + ",";
147 RESTError << "ReplaceMathematicalExpressions. Error on RML syntax!" << RESTendl;
148 if (errorMessage != "") RESTError << errorMessage << RESTendl;
149 } else
150 result += evaluated + ",";
151 }
152 if (Expressions.size() > 0) result.erase(result.size() - 1, 1);
153
154 if (erased) {
155 result = "(" + result + ")";
156 }
157 result = CropWithPrecision(result, precision);
158
159 return result + unit;
160}
161
167 if (!isAExpression(exp)) {
168 return exp;
169 }
170
171// NOTE!!! In root6 the expression like "1/2" will be computed using the input
172// as int number, which will return 0, and cause problem. we roll back to
173// TFormula of version 5
174#if ROOT_VERSION_CODE < ROOT_VERSION(6, 0, 0)
175 TFormula formula("tmp", exp.c_str());
176#else
177 ROOT::v5::TFormula formula("tmp", exp.c_str());
178#endif
179
180 ostringstream sss;
181 Double_t number = formula.EvalPar(0);
182 if (number > 0 && number < 1.e-300) {
183 RESTWarning << "REST_StringHelper::EvaluateExpresssion. Expression not recognized --> " << exp
184 << RESTendl;
185 return (string) "RESTerror";
186 }
187
188 sss << number;
189 string out = sss.str();
190
191 return out;
192}
193
198Int_t REST_StringHelper::GetChar(string hint) {
199 cout << hint << endl;
200 int result = -1;
201 if (gApplication != nullptr && !gApplication->IsRunning()) {
202 auto timer = std::make_unique<TTimer>("gSystem->ProcessEvents();", 50, kFALSE);
203 bool done = false;
204 do {
205 timer->TurnOn();
206 timer->Reset();
207 result = REST_Display_CompatibilityMode ? 1 : getchar();
208 timer->TurnOff();
209 done = true;
210 } while (!done);
211 } else {
212 result = REST_Display_CompatibilityMode ? 1 : getchar();
213 }
214 return result;
215}
216
222 std::string inTrim = Trim(in);
223 return (inTrim.find_first_not_of("-+0123456789.eE") == string::npos && !inTrim.empty());
224}
225
236vector<string> REST_StringHelper::Split(string in, string separator, bool allowBlankString,
237 bool removeWhiteSpaces, int startPos) {
238 vector<string> result;
239
240 int pos = startPos;
241 int front = 0;
242 while (1) {
243 pos = in.find(separator.c_str(), pos + 1);
244 string sub = in.substr(front, pos - front);
245 if (removeWhiteSpaces) sub = RemoveWhiteSpaces(sub);
246 if (allowBlankString || sub != "") {
247 result.push_back(sub);
248 }
249 front = pos + separator.size();
250 if (pos == -1) break;
251 }
252
253 return result;
254}
255
261vector<double> REST_StringHelper::StringToElements(string in, string separator) {
262 vector<double> result;
263 vector<string> vec_str = REST_StringHelper::Split(in, separator);
264 for (unsigned int i = 0; i < vec_str.size(); i++) {
265 double temp = REST_StringHelper::StringToDouble(vec_str[i]);
266 result.push_back(temp);
267 }
268
269 return result;
270}
271
279vector<double> REST_StringHelper::StringToElements(string in, string headChar, string separator,
280 string tailChar) {
281 vector<double> result;
282 size_t startPos = in.find(headChar);
283 size_t endPos = in.find(tailChar);
284 if (startPos == string::npos || endPos == string::npos) {
285 return result;
286 }
287 vector<string> values = Split(in.substr(startPos + 1, endPos - startPos - 1), ",");
288
289 for (unsigned int i = 0; i < values.size(); i++) {
290 double temp = REST_StringHelper::StringToDouble(values[i]);
291 result.push_back(temp);
292 }
293
294 return result;
295}
296
301 string out = in;
302 size_t pos = 0;
303 while ((pos = out.find(" ", pos)) != string::npos) {
304 out.erase(pos, 1);
305 }
306
307 return out;
308}
309
310ULong64_t REST_StringHelper::ToHash(string str) {
311 ULong64_t prime = 0x100000001B3ull;
312 ULong64_t basis = 0xCBF29CE484222325ull;
313 ULong64_t ret{basis};
314
315 for (unsigned int i = 0; i < str.size(); i++) {
316 ret ^= str[i];
317 ret *= prime;
318 }
319
320 return ret;
321}
322
327Int_t REST_StringHelper::Count(string in, string substring) {
328 int count = 0;
329 size_t nPos = in.find(substring, 0); // First occurrence
330 while (nPos != string::npos) {
331 count++;
332 nPos = in.find(substring, nPos + 1);
333 }
334
335 return count;
336}
337
341Int_t REST_StringHelper::FindNthStringPosition(const string& in, size_t pos, const string& strToFind,
342 size_t nth) {
343 size_t found_pos = in.find(strToFind, pos);
344 if (nth == 0 || string::npos == found_pos) return found_pos;
345 return FindNthStringPosition(in, found_pos + 1, strToFind, nth - 1);
346}
347
366Bool_t REST_StringHelper::MatchString(string str, string matcher) {
367 if (str.size() > 256 || matcher.size() > 256) {
368 RESTError << "REST_StringHelper::MatchString(): string size too large" << RESTendl;
369 return false;
370 }
371
372 vector<vector<bool>> dp(256, vector<bool>(256));
373 int n2 = str.size();
374 int n1 = matcher.size();
375 dp[0][0] = true;
376 int i = 0, j = 0;
377 for (int i = 0; i < n1; i++) {
378 if (matcher[i] != '*') {
379 break;
380 }
381 if (i == n1 - 1 && matcher[i] == '*') {
382 return true;
383 }
384 }
385 for (i = 1; matcher.at(i - 1) == '*'; i++) {
386 dp[i][0] = true;
387 }
388 for (i = 1; i <= n1; i++) {
389 for (j = 1; j <= n2; j++) {
390 if (matcher.at(i - 1) == '*' && (dp[i - 1][j - 1] || dp[i][j - 1] || dp[i - 1][j])) {
391 dp[i][j] = true;
392 } else if (matcher.at(i - 1) == '?' && dp[i - 1][j - 1]) {
393 dp[i][j] = true;
394 } else if (matcher.at(i - 1) == str.at(j - 1) && dp[i - 1][j - 1]) {
395 dp[i][j] = true;
396 }
397 }
398 }
399 if (dp[n1][n2]) {
400 return true;
401 } else {
402 return false;
403 }
404
405 return false;
406}
407
428Int_t REST_StringHelper::DiffString(const string& source, const string& target) {
429 int n = source.length();
430 int m = target.length();
431 if (m == 0) return n;
432 if (n == 0) return m;
433 // Construct a matrix
434 typedef vector<vector<int>> Tmatrix;
435 Tmatrix matrix(n + 1);
436 for (int i = 0; i <= n; i++) matrix[i].resize(m + 1);
437
438 // step 2 Initialize
439
440 for (int i = 1; i <= n; i++) matrix[i][0] = i;
441 for (int i = 1; i <= m; i++) matrix[0][i] = i;
442
443 // step 3
444 for (int i = 1; i <= n; i++) {
445 const char si = source[i - 1];
446 // step 4
447 for (int j = 1; j <= m; j++) {
448 const char dj = target[j - 1];
449 // step 5
450 int cost;
451 if (si == dj) {
452 cost = 0;
453 } else {
454 cost = 1;
455 }
456 // step 6
457 const int above = matrix[i - 1][j] + 1;
458 const int left = matrix[i][j - 1] + 1;
459 const int diag = matrix[i - 1][j - 1] + cost;
460 matrix[i][j] = min(above, min(left, diag));
461 }
462 } // step7
463 return matrix[n][m];
464}
465
470string REST_StringHelper::Replace(string in, string thisString, string byThisString, size_t fromPosition,
471 Int_t N) {
472 string out = in;
473 size_t pos = fromPosition;
474 Int_t cont = 0;
475 while ((pos = out.find(thisString, pos)) != string::npos) {
476 out.replace(pos, thisString.length(), byThisString);
477 pos = pos + byThisString.length();
478 cont++;
479
480 if (N > 0 && cont == N) return out;
481 }
482
483 return out;
484}
485
486string REST_StringHelper::EscapeSpecialLetters(string in) {
487 string result = Replace(in, "(", "\\(", 0);
488 result = Replace(result, ")", "\\)", 0);
489 result = Replace(result, "$", "\\$", 0);
490 result = Replace(result, "#", "\\#", 0);
491 result = Replace(result, "{", "\\{", 0);
492 result = Replace(result, "}", "\\}", 0);
493 result = Replace(result, "<", "\\<", 0);
494 result = Replace(result, ">", "\\>", 0);
495 return result;
496}
497
509 tm* tm_ = localtime(&time);
510 int year, month, day, hour, minute, second;
511 year = tm_->tm_year + 1900;
512 month = tm_->tm_mon + 1;
513 day = tm_->tm_mday;
514 hour = tm_->tm_hour;
515 minute = tm_->tm_min;
516 second = tm_->tm_sec;
517
518 string yearStr = IntegerToString(year);
519 std::string monthStr = IntegerToString(month, "%02d");
520 std::string dayStr = IntegerToString(day, "%02d");
521 std::string hourStr = IntegerToString(hour, "%02d");
522 std::string minuteStr = IntegerToString(minute, "%02d");
523 std::string secondStr = IntegerToString(second, "%02d");
524
525 std::string date =
526 yearStr + "/" + monthStr + "/" + dayStr + " " + hourStr + ":" + minuteStr + ":" + secondStr;
527 return date;
528}
529
546 struct tm tm1;
547 tm1.tm_hour = 0;
548 tm1.tm_min = 0;
549 tm1.tm_sec = 0;
550 time_t time1;
551 if (time.find(":") != string::npos) {
552 if (time.find("/") != string::npos)
553 sscanf(time.c_str(), "%d/%d/%d %d:%d:%d", &(tm1.tm_year), &(tm1.tm_mon), &(tm1.tm_mday),
554 &(tm1.tm_hour), &(tm1.tm_min), &(tm1.tm_sec));
555 else
556 sscanf(time.c_str(), "%d-%d-%d %d:%d:%d", &(tm1.tm_year), &(tm1.tm_mon), &(tm1.tm_mday),
557 &(tm1.tm_hour), &(tm1.tm_min), &(tm1.tm_sec));
558 } else {
559 if (time.find("/") != string::npos)
560 sscanf(time.c_str(), "%d/%d/%d", &(tm1.tm_year), &(tm1.tm_mon), &(tm1.tm_mday));
561 else
562 sscanf(time.c_str(), "%d-%d-%d", &(tm1.tm_year), &(tm1.tm_mon), &(tm1.tm_mday));
563 }
564
565 tm1.tm_year -= 1900;
566 tm1.tm_mon--;
567 tm1.tm_isdst = -1;
568 time1 = mktime(&tm1);
569
570 return time1;
571}
572
573TRestStringOutput::REST_Verbose_Level REST_StringHelper::StringToVerboseLevel(string in) {
574 if (ToUpper(in) == "SILENT" || in == "0") return TRestStringOutput::REST_Verbose_Level::REST_Silent;
575 if (ToUpper(in) == "ESSENTIAL" || ToUpper(in) == "WARNING" || in == "1")
577 if (ToUpper(in) == "INFO" || in == "2") return TRestStringOutput::REST_Verbose_Level::REST_Info;
578 if (ToUpper(in) == "DEBUG" || in == "3") return TRestStringOutput::REST_Verbose_Level::REST_Debug;
579 if (ToUpper(in) == "EXTREME" || in == "4") return TRestStringOutput::REST_Verbose_Level::REST_Extreme;
580
582}
583
588 if (isANumber(in)) {
589 return stod(in);
590 } else {
591 return -1;
592 }
593}
594
599 if (isANumber(in)) {
600 return stof(in);
601 } else {
602 return -1;
603 }
604}
605
610 // If we find a hexadecimal number
611 if (in.find("0x") != string::npos) return (Int_t)stoul(in, nullptr, 16);
612
613 return (Int_t)StringToDouble(in);
614}
615
619string REST_StringHelper::IntegerToString(Int_t n, string format) { return Form(format.c_str(), n); }
620
624string REST_StringHelper::DoubleToString(Double_t d, string format) { return Form(format.c_str(), d); }
625
626Bool_t REST_StringHelper::StringToBool(string booleanString) {
627 const auto booleanStringUpper = ToUpper(booleanString);
628 return booleanStringUpper == "TRUE" || booleanStringUpper == "ON" ||
629 booleanStringUpper == to_string(true);
630}
631
632Long64_t REST_StringHelper::StringToLong(string in) {
633 if (in.find_first_of("eE") != string::npos) {
634 // in case for scientific numbers
635 return (Long64_t)StringToDouble(in);
636 }
637 stringstream strIn;
638 strIn << in;
639 long long llNum;
640 strIn >> llNum;
641 return llNum;
642}
643
648 TVector3 a;
649
650 size_t startVector = in.find_first_of("(");
651 if (startVector == string::npos) return a;
652
653 size_t endVector = in.find_first_of(")");
654 if (endVector == string::npos) return a;
655
656 size_t n = count(in.begin(), in.end(), ',');
657 if (n != 2) return a;
658
659 size_t firstComma = in.find_first_of(",");
660 size_t secondComma = in.find(",", firstComma + 1);
661
662 if (firstComma >= endVector || firstComma <= startVector) return a;
663 if (secondComma >= endVector || secondComma <= startVector) return a;
664
665 string X = in.substr(startVector + 1, firstComma - startVector - 1);
666 string Y = in.substr(firstComma + 1, secondComma - firstComma - 1);
667 string Z = in.substr(secondComma + 1, endVector - secondComma - 1);
668
669 a.SetXYZ(StringToDouble(X), StringToDouble(Y), StringToDouble(Z));
670
671 return a;
672}
673
678 TVector2 a(-1, -1);
679
680 size_t startVector = in.find_first_of("(");
681 if (startVector == string::npos) return a;
682
683 size_t endVector = in.find_first_of(")");
684 if (endVector == string::npos) return a;
685
686 size_t n = count(in.begin(), in.end(), ',');
687 if (n != 1) return a;
688
689 size_t firstComma = in.find_first_of(",");
690
691 if (firstComma >= endVector || firstComma <= startVector) return a;
692
693 string X = in.substr(startVector + 1, firstComma - startVector - 1);
694 string Y = in.substr(firstComma + 1, endVector - firstComma - 1);
695
696 a.Set(StringToDouble(X), StringToDouble(Y));
697
698 return a;
699}
700
705 transform(s.begin(), s.end(), s.begin(), (int (*)(int))toupper);
706 return s;
707}
708
713 if (s.length() == 0) return s;
714 s[0] = *REST_StringHelper::ToUpper(string(&s[0], 1)).c_str();
715 return s;
716}
717
722 transform(s.begin(), s.end(), s.begin(), (int (*)(int))tolower);
723 return s;
724}
725
730string REST_StringHelper::RightTrim(string s, const char* t) {
731 s.erase(s.find_last_not_of(t) + 1);
732 return s;
733}
734
739string REST_StringHelper::LeftTrim(string s, const char* t) {
740 s.erase(0, s.find_first_not_of(t));
741 return s;
742}
743
748string REST_StringHelper::Trim(string s, const char* t) { return LeftTrim(RightTrim(s, t), t); }
749
754 s = Trim(s);
755 s = ToUpper(s);
756 return s;
757}
758
763 s = Trim(s);
764 s = ToLower(s);
765 return s;
766}
767
776 if (name == "") {
777 return "";
778 }
779 if (name[0] == 'f' && name.size() > 1 && (name[1] >= 65 && name[1] <= 90)) {
780 return string(1, tolower(name[1])) + name.substr(2, -1);
781 } else {
782 return "";
783 }
784}
785
794 if (name == "") {
795 return "";
796 }
797 if (islower(name[0])) {
798 return "f" + string(1, toupper(name[0])) + name.substr(1, -1);
799 } else {
800 return "";
801 }
802}
803
836TF1* REST_StringHelper::CreateTF1FromString(string func, double init, double end) {
837 string tf1 = func;
838 // Number of parameters
839 size_t n = count(func.begin(), func.end(), '[');
840 // Reading options
841 int a = 0;
842 vector<int> optPos(n);
843 vector<string> options(n); // Vector of strings of any size.
844 for (unsigned int i = 0; i < n; i++) {
845 optPos[i] = func.find("[", a);
846 options[i] =
847 func.substr(func.find("[", a) + 1, func.find("]", func.find("[", a)) - func.find("[", a) - 1);
848 a = func.find("[", a) + 1;
849 }
850 // Removing options from function string
851 for (unsigned int i = 0; i < n; i++) {
852 tf1.replace(optPos[n - 1 - i] + 1, (func.find("]", optPos[n - 1 - i]) - optPos[n - 1 - i] - 1),
853 string(1, func[optPos[n - 1 - i] + 1]));
854 }
855
856 // Function
857 const char* tf1c = tf1.c_str();
858 TF1* f = new TF1("f", tf1c, init, end);
859
860 // Initial conditions
861 for (unsigned int i = 0; i < n; i++) {
862 if (options[i].find("=") != string::npos) {
863 string op = options[i].substr(options[i].find_last_of("=") + 1,
864 options[i].find("(") - options[i].find_last_of("=") - 1);
865 if (isANumber(op)) {
866 f->SetParameter(i, stod(op));
867 } else {
868 cout << "Initial condition for parameter " << i << " is not a number: " << op << endl;
869 }
870 } else {
871 cout << "No initial condition given for parameter " << i << "!" << endl;
872 }
873 }
874
875 // Fixed values
876 for (unsigned int i = 0; i < n; i++) {
877 if (count(options[i].begin(), options[i].end(), '=') == 2) {
878 string op = options[i].substr(options[i].find_last_of("=") + 1,
879 options[i].find("(") - options[i].find_last_of("=") - 1);
880 if (isANumber(op)) {
881 f->FixParameter(i, stod(op));
882 }
883 // cout << "Parameter " << i << " fixed with value " << op << endl;
884 }
885 }
886
887 // Ranges
888 for (unsigned int i = 0; i < n; i++) {
889 if (options[i].find("(") != string::npos) {
890 string op =
891 options[i].substr(options[i].find("(") + 1, options[i].find(")") - options[i].find("(") - 1);
892 f->SetParLimits(i, stod(op.substr(0, op.find(","))),
893 stod(op.substr(op.find(",") + 1, op.size() - 1 - op.find(","))));
894 // cout << "Parameter " << i << " range " << "(" << stod(op.substr(0, op.find(","))) << "," <<
895 // stod(op.substr(op.find(",")+1, op.size()-1-op.find(",") )) << ")" << endl;
896 }
897 }
898
899 return f;
900}
REST_Verbose_Level
Enumerate of verbose level, containing five levels.
@ REST_Essential
+show some essential information, as well as warnings
@ REST_Info
+show most of the information for each steps
@ REST_Debug
+show the defined debug messages
@ REST_Silent
show minimum information of the software, as well as error messages
Int_t GetChar(std::string hint="Press a KEY to continue ...")
Helps to pause the program, printing a message before pausing.
std::string IntegerToString(Int_t n, std::string format="%d")
Gets a string from an integer.
std::string FirstToUpper(std::string s)
Convert the first character of a string to upper case.
time_t StringToTimeStamp(std::string time)
A method to convert a date/time formatted string to a timestamp.
Float_t StringToFloat(std::string in)
Gets a float from a string.
std::vector< std::string > Split(std::string in, std::string separator, bool allowBlankString=false, bool removeWhiteSpaces=false, int startPos=-1)
Split the input string according to the given separator. Returning a vector of fragments.
Bool_t MatchString(std::string str, std::string matcher)
This method matches a string with certain matcher. Returns true if matched. Supports wildcard charact...
std::string RightTrim(std::string s, const char *t=" \t\n\r\f\v")
Removes all white spaces found at the end of the string (https://stackoverflow.com/questions/216823/w...
Double_t StringToDouble(std::string in)
Gets a double from a string.
TF1 * CreateTF1FromString(std::string func, double init, double end)
Reads a function with parameter options from string and returns it as TF1*.
std::string ToUpper(std::string in)
Convert string to its upper case. Alternative of TString::ToUpper.
Int_t StringToInteger(std::string in)
Gets an integer from a string.
Int_t isAExpression(const std::string &in)
Returns 1 only if valid mathematical expression keywords (or numbers) are found in the string in....
std::string TrimAndUpper(std::string s)
It trims and uppers the string.
TVector2 StringTo2DVector(std::string in)
Gets a 2D-vector from a string.
std::string LeftTrim(std::string s, const char *t=" \t\n\r\f\v")
Removes all white spaces found at the beginning of the string (https://stackoverflow....
std::string EvaluateExpression(std::string exp)
Evaluates a complex numerical expression and returns the resulting value using TFormula.
std::string TrimAndLower(std::string s)
It trims and lowers the string.
Int_t Count(std::string s, std::string sbstring)
Counts the number of occurences of substring inside the input string in.
Int_t DiffString(const std::string &source, const std::string &target)
Returns the number of different characters between two strings.
std::string Trim(std::string s, const char *t=" \t\n\r\f\v")
Removes all white spaces found at the beginning and the end of the string (https://stackoverflow....
std::string ParameterNameToDataMemberName(std::string name)
Convert parameter name to datamember name, following REST parameter naming convention.
std::string ToLower(std::string in)
Convert string to its lower case. Alternative of TString::ToLower.
std::string DataMemberNameToParameterName(std::string name)
Convert data member name to parameter name, following REST parameter naming convention.
Int_t isANumber(std::string in)
Returns 1 only if a valid number is found in the string in. If not it returns 0.
TVector3 StringTo3DVector(std::string in)
Gets a 3D-vector from a string. Format should be : (X,Y,Z).
Int_t FindNthStringPosition(const std::string &in, size_t pos, const std::string &strToFind, size_t nth)
Returns the position of the nth occurence of the string strToFind inside the string in.
std::string RemoveWhiteSpaces(std::string in)
Returns the input string removing all white spaces.
std::string CropWithPrecision(std::string in, Int_t precision)
It crops a floating number given inside the string in with the given precision. I....
std::vector< double > StringToElements(std::string in, std::string separator)
Convert the input string into a vector of double elements.
std::string ToDateTimeString(time_t time)
Format time_t into string.
std::string DoubleToString(Double_t d, std::string format="%4.2lf")
Gets a string from a double.
std::string Replace(std::string in, std::string thisString, std::string byThisString, size_t fromPosition=0, Int_t N=0)
Replace every occurences of thisSring by byThisString inside string in.
std::string ReplaceMathematicalExpressions(std::string buffer, Int_t precision=0, std::string errorMessage="")
Evaluates and replaces valid mathematical expressions found in the input string buffer.