36 static std::optional<Address>
parse(std::string_view text) {
37 if (!text.empty() && text.front() ==
'[') {
39 const auto close = text.find(
']');
40 if (close == std::string_view::npos || close + 1 >= text.size() || text[close + 1] !=
':')
42 const auto host = text.substr(1, close - 1);
43 if (host.empty())
return std::nullopt;
44 const auto port = parse_port(text.substr(close + 2));
45 if (!
port)
return std::nullopt;
48 const auto colon = text.rfind(
':');
49 if (colon == std::string_view::npos || colon == 0 || colon + 1 == text.size())
51 const auto host = text.substr(0, colon);
54 if (host.find(
':') != std::string_view::npos)
return std::nullopt;
55 const auto port = parse_port(text.substr(colon + 1));
56 if (!
port)
return std::nullopt;