SplitStr add support for comma and space delims

This commit is contained in:
dimxy
2019-04-09 12:40:44 +05:00
parent dc1257a85d
commit dee17205d2

View File

@@ -394,27 +394,25 @@ void ParseParameters(int argc, const char* const argv[])
} }
} }
// split string using by space or comma as delimiter char
void SplitStr(const std::string& strVal, std::vector<std::string> &outVals) void SplitStr(const std::string& strVal, std::vector<std::string> &outVals)
{ {
stringstream ss(strVal); stringstream ss(strVal);
std::string str;
while ( ss.peek() == ' ' ) while (true) {
ss.ignore(); int c;
std::string str;
while ( ss >> str )
{ while (std::isspace(ss.peek()))
if ( str.size() == 0 )
continue;
if ( str[str.size()-1] == ',' )
str.resize(str.size()-1);
outVals.push_back(str);
while ( ss.peek() == ' ' )
ss.ignore();
if ( ss.peek() == ',' )
ss.ignore();
while ( ss.peek() == ' ' )
ss.ignore(); ss.ignore();
while (!ss.eofbit && !std::isspace(c = ss.get() && c != ','))
str += c;
if (!str.empty())
outVals.push_back(str);
else
break;
} }
} }