36 template<
typename Out>
37 void splitString(
const std::string &iString,
char iDelimiter, Out oResult,
bool iSkipEmptyEntries =
false)
39 std::stringstream ss(iString);
41 while(std::getline(ss, item, iDelimiter))
43 if(!item.empty() || !iSkipEmptyEntries)
46 if(!iSkipEmptyEntries)
48 if(!iString.empty() && iString[iString.size() - 1] == iDelimiter)
60 std::vector<std::string>
splitString(
const std::string &iString,
char iDelimiter,
bool iSkipEmptyEntries =
false);
67 template<
typename TFloat>
70 char *endPtr =
nullptr;
71 auto value = static_cast<TFloat>(strtod(iString.c_str(), &endPtr));
72 if(endPtr == iString.c_str())
83 template<
typename TFloat>
86 char *endPtr =
nullptr;
87 auto value = static_cast<TFloat>(strtod(iString.c_str(), &endPtr));
88 if(endPtr == iString.c_str())
89 return std::numeric_limits<TFloat>::quiet_NaN();
98 template<
typename TFloat>
99 std::vector<TFloat>
splitFloats(
const std::string &iString,
char iDelimiter,
bool iSkipEmptyEntries =
false)
101 static auto f = [] (
const std::string &iString) -> TFloat {
return stringToFloat<TFloat>(iString); };
103 std::vector<TFloat> res{};
105 auto strings =
splitString(iString, iDelimiter, iSkipEmptyEntries);
109 res.reserve(strings.size());
111 std::transform(strings.cbegin(), strings.cend(), std::back_inserter(res), f);
std::vector< TFloat > splitFloats(const std::string &iString, char iDelimiter, bool iSkipEmptyEntries=false)
Definition: StringUtils.h:99
std::vector< std::string > splitString(const std::string &iString, char iDelimiter, bool iSkipEmptyEntries)
Definition: StringUtils.cpp:30
bool stringToFloat(const std::string &iString, TFloat &oValue)
Definition: StringUtils.h:68