2#ifndef RestTools_REST_StringHelper
3#define RestTools_REST_StringHelper
22#include "TRestStringOutput.h"
27Int_t
GetChar(std::string hint =
"Press a KEY to continue ...");
32 std::string errorMessage =
"");
39std::string
DoubleToString(Double_t d, std::string format =
"%8.6e");
40Bool_t StringToBool(std::string booleanString);
41Long64_t StringToLong(std::string in);
44std::vector<std::string>
Split(std::string in, std::string separator,
bool allowBlankString =
false,
45 bool removeWhiteSpaces =
false,
int startPos = -1);
47std::vector<double>
StringToElements(std::string in, std::string headChar, std::string separator,
48 std::string tailChar);
51std::string
Replace(std::string in, std::string thisString, std::string byThisString,
size_t fromPosition = 0,
53std::string EscapeSpecialLetters(std::string in);
57ULong64_t ToHash(std::string str);
58constexpr ULong64_t ToHash(
const char* str, ULong64_t last_value = 0xCBF29CE484222325ull) {
59 return *str ? ToHash(str + 1, (*str ^ last_value) * 0x100000001B3ull) : last_value;
61Int_t
Count(std::string s, std::string sbstring);
62Int_t
FindNthStringPosition(
const std::string& in,
size_t pos,
const std::string& strToFind,
size_t nth);
63Bool_t
MatchString(std::string str, std::string matcher);
64Int_t
DiffString(
const std::string& source,
const std::string& target);
66std::string ToString(T source,
int length = -1,
char fill =
' ') {
67 std::stringstream ss1;
69 std::string s = ss1.str();
72 }
else if (s.size() < (
unsigned int)length) {
73 return s + std::string(length - s.size(), fill);
75 return s.substr(0, length);
80std::string StringWithPrecision(T& value,
int precision) {
82 ss.precision(precision);
88template <
class T1,
class T2>
89inline std::vector<T2> Vector_cast(std::vector<T1> vecstring) {
90 std::vector<T2> result;
91 for (T1 s : vecstring) {
92 result.push_back((T2)s);
97std::string
ToUpper(std::string in);
98std::string
ToLower(std::string in);
102std::string
RightTrim(std::string s,
const char* t =
" \t\n\r\f\v");
103std::string
LeftTrim(std::string s,
const char* t =
" \t\n\r\f\v");
104std::string
Trim(std::string s,
const char* t =
" \t\n\r\f\v");
118inline void setenv(
const char* __name,
const char* __value,
int __replace) {
119 _putenv(((std::string)__name +
"=" + (std::string)__value).c_str());
121inline int getpid() {
return _getpid(); }
122inline int fileno(FILE* fp) {
return _fileno(fp); }
124inline void usleep(
int usec) {
131inline void sleep(
int sec) { _sleep(1000 * sec); }
132#define __PRETTY_FUNCTION__ __FUNCTION__
133#define M_PI 3.14159265358979323846
REST_Verbose_Level
Enumerate of verbose level, containing five levels.
String helper classes. Declared static to be able to have direct access to the methods.
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 DoubleToString(Double_t d, std::string format="%8.6e")
Gets a string from a double.
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::vector< int > IntegerToBinary(int number, size_t dimension=0)
It returns an integer vector with the binary digits decomposed.
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 RemoveDelimiters(std::string in)
Returns the input string removing any delimiters ({[]})
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 Replace(std::string in, std::string thisString, std::string byThisString, size_t fromPosition=0, Int_t N=0)
Replace any 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.