| 173 | } |
| 174 | |
| 175 | Status HostPort::ParseString(const string& str, uint16_t default_port) { |
| 176 | std::pair<string, string> p = strings::Split(str, strings::delimiter::Limit(":", 1)); |
| 177 | |
| 178 | // Strip any whitespace from the host. |
| 179 | StripWhiteSpace(&p.first); |
| 180 | |
| 181 | // Parse the port. |
| 182 | uint32_t port; |
| 183 | if (p.second.empty() && strcount(str, ':') == 0) { |
| 184 | // No port specified. |
| 185 | port = default_port; |
| 186 | } else if (!SimpleAtoi(p.second, &port) || |
| 187 | port > 65535) { |
| 188 | return Status::InvalidArgument("invalid port", str); |
| 189 | } |
| 190 | |
| 191 | host_.swap(p.first); |
| 192 | port_ = port; |
| 193 | return Status::OK(); |
| 194 | } |
| 195 | |
| 196 | Status HostPort::ParseStringWithScheme(const string& str, uint16_t default_port) { |
| 197 | string str_copy(str); |