summaryrefslogtreecommitdiffstats
path: root/lldb/source/Utility
diff options
context:
space:
mode:
authorZachary Turner <zturner@google.com>2016-11-17 01:38:02 +0000
committerZachary Turner <zturner@google.com>2016-11-17 01:38:02 +0000
commit245f7fdcfa9fb4351f53ab9d96b31e1e472e81bd (patch)
tree6ff373d6c04675d624f323b6452d3c5da1eac12f /lldb/source/Utility
parent24bd3178714d8f9f10d0fd4c1a4de2605da20404 (diff)
downloadbcm5719-llvm-245f7fdcfa9fb4351f53ab9d96b31e1e472e81bd.tar.gz
bcm5719-llvm-245f7fdcfa9fb4351f53ab9d96b31e1e472e81bd.zip
Convert UriParser to use StringRef.
llvm-svn: 287190
Diffstat (limited to 'lldb/source/Utility')
-rw-r--r--lldb/source/Utility/UriParser.cpp36
-rw-r--r--lldb/source/Utility/UriParser.h8
2 files changed, 19 insertions, 25 deletions
diff --git a/lldb/source/Utility/UriParser.cpp b/lldb/source/Utility/UriParser.cpp
index 6a1f0303b97..a1d6e4c3d85 100644
--- a/lldb/source/Utility/UriParser.cpp
+++ b/lldb/source/Utility/UriParser.cpp
@@ -23,18 +23,19 @@ using namespace lldb_private;
//----------------------------------------------------------------------
// UriParser::Parse
//----------------------------------------------------------------------
-bool UriParser::Parse(const std::string &uri, std::string &scheme,
- std::string &hostname, int &port, std::string &path) {
- std::string tmp_scheme, tmp_hostname, tmp_port, tmp_path;
+bool UriParser::Parse(llvm::StringRef uri, llvm::StringRef &scheme,
+ llvm::StringRef &hostname, int &port,
+ llvm::StringRef &path) {
+ llvm::StringRef tmp_scheme, tmp_hostname, tmp_port, tmp_path;
- static const char *kSchemeSep = "://";
+ const llvm::StringRef kSchemeSep("://");
auto pos = uri.find(kSchemeSep);
if (pos == std::string::npos)
return false;
// Extract path.
tmp_scheme = uri.substr(0, pos);
- auto host_pos = pos + strlen(kSchemeSep);
+ 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);
@@ -53,28 +54,19 @@ bool UriParser::Parse(const std::string &uri, std::string &scheme,
return false;
tmp_hostname = host_port.substr(1, pos - 1);
- host_port.erase(0, pos + 1);
+ host_port = host_port.drop_front(pos + 1);
+ if (!host_port.empty() && !host_port.consume_front(":"))
+ return false;
} else {
- pos = host_port.find(':');
- tmp_hostname = host_port.substr(
- 0, (pos != std::string::npos) ? pos : host_port.size());
- host_port.erase(0, (pos != std::string::npos) ? pos : host_port.size());
+ std::tie(tmp_hostname, host_port) = host_port.split(':');
}
// Extract port
- tmp_port = host_port;
- if (!tmp_port.empty()) {
- if (tmp_port[0] != ':')
- return false;
- tmp_port = tmp_port.substr(1);
- bool success = false;
- auto port_tmp =
- StringConvert::ToUInt32(tmp_port.c_str(), UINT32_MAX, 10, &success);
- if (!success || port_tmp > 65535) {
- // there are invalid characters in port_buf
+ if (!host_port.empty()) {
+ uint16_t port_value = 0;
+ if (host_port.getAsInteger(0, port_value))
return false;
- }
- port = port_tmp;
+ port = port_value;
} else
port = -1;
diff --git a/lldb/source/Utility/UriParser.h b/lldb/source/Utility/UriParser.h
index 56bd194ae64..7ebf76f89ca 100644
--- a/lldb/source/Utility/UriParser.h
+++ b/lldb/source/Utility/UriParser.h
@@ -12,9 +12,10 @@
// C Includes
// C++ Includes
-#include <string>
// Other libraries and framework includes
+#include "llvm/ADT/StringRef.h"
+
// Project includes
class UriParser {
@@ -27,8 +28,9 @@ public:
//
// if the url is invalid, function returns false and
// output parameters remain unchanged
- static bool Parse(const std::string &uri, std::string &scheme,
- std::string &hostname, int &port, std::string &path);
+ static bool Parse(llvm::StringRef uri, llvm::StringRef &scheme,
+ llvm::StringRef &hostname, int &port,
+ llvm::StringRef &path);
};
#endif // utility_UriParser_h_
OpenPOWER on IntegriCloud