Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct URL
- {
- std::string Schema;
- std::string User;
- std::string Pass;
- std::string Host;
- uint32_t Port;
- std::string Path;
- std::string Query;
- };
- static bool parse_url(std::string url, URL &u)
- {
- boost::regex re("(\\w+)://(([1-9a-zA-Z_]*):([1-9a-zA-Z_]*)@)?([^:/]+)(:(\\d+))?(/[^?]+)?(\\?(.*))?");
- boost::smatch m;
- if (!boost::regex_match(url, m, re))
- {
- return false;
- }
- u.Schema = m[1];
- u.Host = m[5];
- u.User = m[3];
- u.Pass = m[4];
- if (m[7].length() > 0)
- {
- u.Port = boost::lexical_cast<uint32_t>(m[7]);
- }
- u.Path = m[8];
- u.Query = m[10];
- return true;
- }
Add Comment
Please, Sign In to add comment