14 #ifndef STRING_UTILS_H 15 #define STRING_UTILS_H 26 inline std::string
strip(
const std::string&
s)
28 int start =
s.length();
31 for (i = 0; i <
s.length(); i++)
33 if (
s[i] !=
' ' &&
s[i] !=
'\n' &&
s[i] !=
'\t')
39 for (i =
s.length() - 1; i > 0; i--)
41 if (
s[i] !=
' ' &&
s[i] !=
'\n' &&
s[i] !=
'\t')
50 return s.substr(start, end - start + 1);
54 inline bool whitespace(
char c) {
return (c ==
' ' || c ==
'\n' || c ==
'\t'); }
57 inline std::vector<std::string>
split(
const std::string&
s)
59 std::vector<std::string> tokens;
61 while (i <
s.length())
69 int len = end - start;
71 tokens.push_back(
s.substr(start, len));
77 inline std::vector<std::string>
split(
const std::string&
s,
const std::string& pattern)
81 int plen = pattern.length();
83 std::vector<std::string> tokens;
87 eloc =
s.find(pattern, sloc);
88 if (eloc != std::string::npos)
90 ss =
s.substr(sloc, eloc - sloc);
102 ss =
s.substr(sloc, eloc - sloc);
107 tokens.push_back(ss);
115 inline int string2int(
const std::string&
s) {
return atoi(
s.c_str()); }
121 std::stringstream ss;
128 std::stringstream ss;
135 if (
s ==
"true" ||
s ==
"yes" ||
s ==
"1")
139 else if (
s ==
"false" ||
s ==
"no" ||
s ==
"0")
145 throw std::runtime_error(
"string2bool received non-boolean string: " +
s);
154 std::istringstream stream(
s);
156 while (!stream.eof())
158 if (T t; stream >> t)
160 else if (!stream.eof() && stream.fail())
162 std::ostringstream msg;
163 msg <<
"Error parsing string '" <<
s <<
"' for type (type_info::name) " <<
typeid(T).name() <<
"." << std::endl;
164 throw std::runtime_error(msg.str());
180 is.getline(buf, 256);
187 os << rhs.
s << std::endl;
helper functions for EinsplineSetBuilder
std::vector< T > convertStrToVec(const std::string &s)
extract the contents of a string to a vector of something. separator is white spaces.
std::string int2string(const int &i)
bool operator==(const Matrix< T, Alloc > &lhs, const Matrix< T, Alloc > &rhs)
std::string strip(const std::string &s)
int string2int(const std::string &s)
std::vector< std::string > split(const std::string &s)
std::string real2string(const double &r)
std::ostream & operator<<(std::ostream &out, const AntiSymTensor< T, D > &rhs)
double string2real(const std::string &s)
bool string2bool(const std::string &s)
std::istream & operator>>(std::istream &is, Matrix< T, Alloc > &rhs)