mirror of https://github.com/qt/qtgrpc.git
tools [utils]: directly emplace substrings into vector for split()
Saves a temporary. Change-Id: I6851e6f941dfa593fb37f79a7ec19ce446753556 Pick-to: 6.9 6.8 Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
This commit is contained in:
parent
0e6a9f6890
commit
a335b71abe
|
@ -32,16 +32,15 @@ std::vector<std::string> split(std::string_view s, std::string_view c, bool keep
|
|||
assert(!c.empty());
|
||||
std::vector<std::string> out;
|
||||
std::string::size_type pos = 0;
|
||||
std::string item;
|
||||
for (std::string::size_type posNext = 0; (posNext = s.find(c, pos)) != std::string::npos;
|
||||
pos = posNext + c.size()) {
|
||||
item = s.substr(pos, posNext - pos);
|
||||
auto item = s.substr(pos, posNext - pos);
|
||||
if (keepEmpty || !item.empty())
|
||||
out.push_back(item);
|
||||
out.emplace_back(item);
|
||||
}
|
||||
item = s.substr(pos);
|
||||
auto item = s.substr(pos);
|
||||
if (keepEmpty || !item.empty())
|
||||
out.push_back(item);
|
||||
out.emplace_back(item);
|
||||
return out;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue