Created
January 9, 2019 08:21
-
-
Save hyqhyq3/bb92d6ebaa79bc131e4f7135a2d0a801 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment