Skip to content

Instantly share code, notes, and snippets.

@ilpropheta
Last active January 2, 2017 21:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ilpropheta/0666a599069305552dbd85467b0a8c87 to your computer and use it in GitHub Desktop.
Save ilpropheta/0666a599069305552dbd85467b0a8c87 to your computer and use it in GitHub Desktop.
vector<string_view> split(string_view str, const char* delims)
{
vector<string_view> ret;
string_view::size_type start = 0;
auto pos = str.find_first_of(delims, start);
while (pos != string_view::npos)
{
if (pos != start)
{
ret.push_back(str.substr(start, pos - start));
}
start = pos + 1;
pos = str.find_first_of(delims, start);
}
if (start < str.length())
ret.push_back(str.substr(start, str.length() - start));
return ret;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment