aboutsummaryrefslogtreecommitdiff
path: root/lldb/source/Utility/UriParser.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lldb/source/Utility/UriParser.cpp')
-rw-r--r--lldb/source/Utility/UriParser.cpp43
1 files changed, 23 insertions, 20 deletions
diff --git a/lldb/source/Utility/UriParser.cpp b/lldb/source/Utility/UriParser.cpp
index c6ed24985896..cfb9009898d2 100644
--- a/lldb/source/Utility/UriParser.cpp
+++ b/lldb/source/Utility/UriParser.cpp
@@ -7,6 +7,7 @@
//===----------------------------------------------------------------------===//
#include "lldb/Utility/UriParser.h"
+#include "llvm/Support/raw_ostream.h"
#include <string>
@@ -15,25 +16,30 @@
using namespace lldb_private;
-// UriParser::Parse
-bool UriParser::Parse(llvm::StringRef uri, llvm::StringRef &scheme,
- llvm::StringRef &hostname, int &port,
- llvm::StringRef &path) {
- llvm::StringRef tmp_scheme, tmp_hostname, tmp_path;
+llvm::raw_ostream &lldb_private::operator<<(llvm::raw_ostream &OS,
+ const URI &U) {
+ OS << U.scheme << "://[" << U.hostname << ']';
+ if (U.port)
+ OS << ':' << U.port.getValue();
+ return OS << U.path;
+}
+
+llvm::Optional<URI> URI::Parse(llvm::StringRef uri) {
+ URI ret;
const llvm::StringRef kSchemeSep("://");
auto pos = uri.find(kSchemeSep);
if (pos == std::string::npos)
- return false;
+ return llvm::None;
// Extract path.
- tmp_scheme = uri.substr(0, pos);
+ ret.scheme = uri.substr(0, pos);
auto host_pos = pos + kSchemeSep.size();
auto path_pos = uri.find('/', host_pos);
if (path_pos != std::string::npos)
- tmp_path = uri.substr(path_pos);
+ ret.path = uri.substr(path_pos);
else
- tmp_path = "/";
+ ret.path = "/";
auto host_port = uri.substr(
host_pos,
@@ -44,27 +50,24 @@ bool UriParser::Parse(llvm::StringRef uri, llvm::StringRef &scheme,
// hostname is enclosed with square brackets.
pos = host_port.rfind(']');
if (pos == std::string::npos)
- return false;
+ return llvm::None;
- tmp_hostname = host_port.substr(1, pos - 1);
+ ret.hostname = host_port.substr(1, pos - 1);
host_port = host_port.drop_front(pos + 1);
if (!host_port.empty() && !host_port.consume_front(":"))
- return false;
+ return llvm::None;
} else {
- std::tie(tmp_hostname, host_port) = host_port.split(':');
+ std::tie(ret.hostname, host_port) = host_port.split(':');
}
// Extract port
if (!host_port.empty()) {
uint16_t port_value = 0;
if (host_port.getAsInteger(0, port_value))
- return false;
- port = port_value;
+ return llvm::None;
+ ret.port = port_value;
} else
- port = -1;
+ ret.port = llvm::None;
- scheme = tmp_scheme;
- hostname = tmp_hostname;
- path = tmp_path;
- return true;
+ return ret;
}