14 Url*
Url::Parse(
const std::string& url,
const std::string& default_protocol,
23 std::string
protocol = default_protocol;
24 size_t sep_pos = url.find(
"://");
25 if (sep_pos != std::string::npos) {
26 protocol = url.substr(0, sep_pos);
32 uint64_t
port = default_port;
35 size_t col_pos = url.find(
":", cursor);
36 if (col_pos != std::string::npos) {
38 host = url.substr(cursor, col_pos - cursor);
41 size_t slash_pos = url.find(
"/", cursor);
49 slash_pos == std::string::npos ? std::string::npos : slash_pos - cursor;
54 if (slash_pos != std::string::npos) {
55 path = url.substr(slash_pos);
59 size_t slash_pos = url.find(
"/", cursor);
60 if (slash_pos != std::string::npos) {
61 host = url.substr(cursor, slash_pos - cursor);
62 path = url.substr(slash_pos);
64 host = url.substr(cursor);
73 return new Url(protocol, host, path, port);
90 Url::Url() : protocol_(), host_(), path_(), port_(), address_() {}
92 Url::Url(
const std::string& protocol,
const std::string& host,
93 const std::string& path,
int port)
94 : protocol_(protocol),
static const char * kDefaultProtocol
static bool ValidateHost(const std::string &host)
std::string protocol() const
bool String2Uint64Parse(const std::string &value, uint64_t *result)
string StringifyInt(const int64_t value)
static Url * Parse(const std::string &url, const std::string &default_protocol=kDefaultProtocol, int default_port=kDefaultPort)
static const int kDefaultPort