Skip to content

Commit d751de4

Browse files
committed
utils.cpp: simplified splitString()
1 parent 7fe105c commit d751de4

1 file changed

Lines changed: 8 additions & 10 deletions

File tree

‎lib/utils.cpp‎

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -188,18 +188,16 @@ std::string replaceEscapeSequences(const std::string &source) {
188188

189189
std::list<std::string> splitString(const std::string& str, char sep)
190190
{
191-
if (std::strchr(str.c_str(), sep) == nullptr)
192-
return {str};
193-
194191
std::list<std::string> l;
195-
std::string p(str);
196-
for (;;) {
197-
const std::string::size_type pos = p.find(sep);
198-
if (pos == std::string::npos)
192+
193+
std::string::size_type pos1 = 0;
194+
std::string::size_type pos2;
195+
while (true) {
196+
pos2 = str.find(sep, pos1);
197+
l.push_back(str.substr(pos1, pos2 - pos1));
198+
if (pos2 == std::string::npos)
199199
break;
200-
l.push_back(p.substr(0,pos));
201-
p = p.substr(pos+1);
200+
pos1 = pos2 + 1;
202201
}
203-
l.push_back(std::move(p));
204202
return l;
205203
}

0 commit comments

Comments
 (0)