Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@cdglove
Last active August 29, 2015 14:17
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 cdglove/a1411fc9c6adc21c7f9c to your computer and use it in GitHub Desktop.
Save cdglove/a1411fc9c6adc21c7f9c to your computer and use it in GitHub Desktop.
void split_csv(std::string raw_csv, std::set<std::string>& dest_set)
{
std::vector<boost::iterator_range<std::string::iterator>> result;
boost::algorithm::split(result, raw_csv, [](char c)
{
return c == ',';
});
boost::transform(result, std::inserter(dest_set, dest_set.begin()),
[](boost::iterator_range<std::string::iterator> r)
{
auto begin = r.begin();
auto end = r.end();
while(begin != end && std::isspace(*begin))
++begin;
while(begin != end && std::isspace(*(end - 1)))
--end;
return std::string(begin, end);
}
);
dest_set.erase("");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment