28 constexpr
char const *
to_string(
bool iValue) {
return iValue ?
"true" :
"false"; }
38 template<
typename Out>
39 void splitString(
const std::string &iString,
char iDelimiter, Out oResult,
bool iSkipEmptyEntries =
false)
41 std::stringstream ss(iString);
43 while(std::getline(ss, item, iDelimiter))
45 if(!item.empty() || !iSkipEmptyEntries)
48 if(!iSkipEmptyEntries)
50 if(!iString.empty() && iString[iString.size() - 1] == iDelimiter)
62 std::vector<std::string>
splitString(
const std::string &iString,
char iDelimiter,
bool iSkipEmptyEntries =
false);
69 template<
typename TFloat>
72 char *endPtr =
nullptr;
73 auto value = static_cast<TFloat>(strtod(iString.c_str(), &endPtr));
74 if(endPtr == iString.c_str())
85 template<
typename TFloat>
88 char *endPtr =
nullptr;
89 auto value = static_cast<TFloat>(strtod(iString.c_str(), &endPtr));
90 if(endPtr == iString.c_str())
91 return std::numeric_limits<TFloat>::quiet_NaN();
100 template<
typename TFloat>
101 std::vector<TFloat>
splitFloats(
const std::string &iString,
char iDelimiter,
bool iSkipEmptyEntries =
false)
103 static auto f = [] (
const std::string &iString) -> TFloat {
return stringToFloat<TFloat>(iString); };
105 std::vector<TFloat> res{};
107 auto strings =
splitString(iString, iDelimiter, iSkipEmptyEntries);
111 res.reserve(strings.size());
113 std::transform(strings.cbegin(), strings.cend(), std::back_inserter(res), f);
std::vector< TFloat > splitFloats(const std::string &iString, char iDelimiter, bool iSkipEmptyEntries=false)
Converts the string to a TFloat.
Definition: StringUtils.h:101
Definition: CircularBuffer.h:25
std::vector< std::string > splitString(const std::string &iString, char iDelimiter, bool iSkipEmptyEntries)
Split a string according to a delimiter and returns a vector.
Definition: StringUtils.cpp:30
bool stringToFloat(const std::string &iString, TFloat &oValue)
Converts the string to a TFloat (float or double)
Definition: StringUtils.h:70
constexpr std::array< U, N > transform(std::array< T, N > const &a, F &&f)
Transforms an array containing elements of type T into an array containing elements of type U by appl...
Definition: stl.h:40
constexpr char const * to_string(bool iValue)
Convenient call to convert a boolean into a string.
Definition: StringUtils.h:28