Fix utils::string::ssplit() to handle delimiter in the end of string

This closes #1743.
This commit is contained in:
Andrei Belov
2018-04-18 11:27:17 +03:00
committed by Felipe Zimmerle
parent 5018358371
commit 5e65d560f8
4 changed files with 82 additions and 2 deletions

View File

@@ -178,9 +178,14 @@ std::vector<std::string> ssplit(std::string str, char delimiter) {
std::vector<std::string> internal;
std::stringstream ss(str); // Turn the string into a stream.
std::string tok;
ssize_t n = str.length();
int i = 0;
while (getline(ss, tok, delimiter)) {
internal.push_back(tok);
n -= tok.length();
if (i > 0) n--;
internal.push_back(n == 1 ? tok + delimiter : tok);
i++;
}
return internal;