10#include "llvm/Support/raw_ostream.h"
31 const llvm::StringRef kSchemeSep(
"://");
32 auto pos = uri.find(kSchemeSep);
33 if (pos == std::string::npos)
37 ret.
scheme = uri.substr(0, pos);
38 auto host_pos = pos + kSchemeSep.size();
39 auto path_pos = uri.find(
'/', host_pos);
40 if (path_pos != std::string::npos)
41 ret.
path = uri.substr(path_pos);
45 auto host_port = uri.substr(
47 ((path_pos != std::string::npos) ? path_pos : uri.size()) - host_pos);
50 if (host_port.starts_with(
'[')) {
52 pos = host_port.rfind(
']');
53 if (pos == std::string::npos)
56 ret.
hostname = host_port.substr(1, pos - 1);
57 host_port = host_port.drop_front(pos + 1);
58 if (!host_port.empty() && !host_port.consume_front(
":"))
61 std::tie(ret.
hostname, host_port) = host_port.split(
':');
65 if (!host_port.empty()) {
66 uint16_t port_value = 0;
67 if (host_port.getAsInteger(0, port_value))
69 ret.
port = port_value;
71 ret.
port = std::nullopt;
A class that represents a running process on the host machine.
Stream & operator<<(Stream &s, const Mangled &obj)
static std::optional< URI > Parse(llvm::StringRef uri)
std::optional< uint16_t > port