Fix string split

This commit is contained in:
Georg Hagen
2024-06-22 19:09:25 +02:00
parent b2941b0fe4
commit 5e612e2700

View File

@@ -143,13 +143,16 @@ namespace OpenVulkano
static std::vector<std::string> Split(const std::string_view& str, char separator)
{
std::vector<std::string> subs;
size_t startPos = 0;
size_t pos = std::string::npos;
size_t startPos = 0, pos;
while ((pos = str.find(separator, startPos)) != std::string::npos)
{
if (startPos == pos) { startPos++; continue; }
subs.emplace_back(str.substr(startPos, pos));
startPos = pos;
if (startPos == pos)
{
startPos++;
continue;
}
subs.emplace_back(str.substr(startPos, pos - startPos));
startPos = pos + 1;
}
if (startPos != str.length() - 1)
subs.emplace_back(str.substr(startPos));