utils.cpp
611 Bytes
#include "utils.h"
std::list<std::__cxx11::string> split(const std::string &input, const char sep, size_t max, bool keep_empty_parts)
{
std::list<std::string> list;
size_t start = 0;
size_t end;
while (list.size() < max && (end = input.find(sep, start)) != std::string::npos)
{
if (start != end || keep_empty_parts)
list.push_back(input.substr(start, end - start));
start = end + 1; // increase by length of seperator.
}
if (start != input.size() || keep_empty_parts)
list.push_back(input.substr(start, std::string::npos));
return list;
}