57[[nodiscard]]
inline std::optional<HostPort>
parse_host_port(std::string_view text)
59 const size_t colon = text.rfind(
':');
60 if (colon == std::string_view::npos) {
64 std::string_view host = text.substr(0, colon);
65 const auto port =
parse_port(text.substr(colon + 1));
70 if (host.size() >= 2 && host.front() ==
'[' && host.back() ==
']') {
71 host = host.substr(1, host.size() - 2);
72 }
else if (host.find(
':') != std::string_view::npos) {
79 for (
const char c : host) {
80 if (
static_cast<unsigned char>(c) <=
' ' || c == 0x7F) {
85 return HostPort { .host = std::string(host), .port = *port };