I need to parse the path part of a URL for a "router" as part of a REST web service. I'm using the PION library for handling HTTP requests. This library does not seem to have any functionality for retrieving parts of the URL path - or so it seems. I cannot find another library that does this. http://www.w3.org/Library/src/HTParse.c does not give parts of the path for example.
Is there a quicker, more robust way of doing this:
std::vector<std::string> parsePath(std::string path)
{
std::string delimiter = "/";
std::string part = "";
std::size_t firstPos = 0;
std::size_t secondPos = 0;
std::vector<std::string> parts;
while (firstPos != std::string::npos)
{
firstPos = path.find(delimiter, firstPos);
secondPos = path.find(delimiter, firstPos + 1);
part = path.substr(firstPos + 1, (secondPos - 1) - firstPos);
if (part != "") parts.push_back(part);
firstPos = secondPos;
}
return parts;
}