summaryrefslogtreecommitdiffstats
path: root/lldb/source/Host/common
diff options
context:
space:
mode:
authorJonas Devlieghere <jonas@devlieghere.com>2019-08-16 21:25:36 +0000
committerJonas Devlieghere <jonas@devlieghere.com>2019-08-16 21:25:36 +0000
commit3af3f1e8e253d93cb655388af69f4ed1722b4f51 (patch)
tree44b9e8ecf404119a1a81b54e27ea6559a5f5dd9a /lldb/source/Host/common
parent250aafa2c4a1bc2395edfe8d4365545bbe56fffe (diff)
downloadbcm5719-llvm-3af3f1e8e253d93cb655388af69f4ed1722b4f51.tar.gz
bcm5719-llvm-3af3f1e8e253d93cb655388af69f4ed1722b4f51.zip
[Utility] Reimplement RegularExpression on top of llvm::Regex
Originally I wanted to remove the RegularExpression class in Utility and replace it with llvm::Regex. However, during that transition I noticed that there are several places where need the regular expression string. So instead I propose to keep the RegularExpression class and make it a thin wrapper around llvm::Regex. This patch also removes the workaround for empty regular expressions. The result is that we are now (more or less) POSIX conformant. Differential revision: https://reviews.llvm.org/D66174 llvm-svn: 369153
Diffstat (limited to 'lldb/source/Host/common')
-rw-r--r--lldb/source/Host/common/Socket.cpp36
1 files changed, 17 insertions, 19 deletions
diff --git a/lldb/source/Host/common/Socket.cpp b/lldb/source/Host/common/Socket.cpp
index 0732565f0d8..9ce36d014f6 100644
--- a/lldb/source/Host/common/Socket.cpp
+++ b/lldb/source/Host/common/Socket.cpp
@@ -282,27 +282,25 @@ bool Socket::DecodeHostAndPort(llvm::StringRef host_and_port,
int32_t &port, Status *error_ptr) {
static RegularExpression g_regex(
llvm::StringRef("([^:]+|\\[[0-9a-fA-F:]+.*\\]):([0-9]+)"));
- RegularExpression::Match regex_match(2);
- if (g_regex.Execute(host_and_port, &regex_match)) {
- if (regex_match.GetMatchAtIndex(host_and_port, 1, host_str) &&
- regex_match.GetMatchAtIndex(host_and_port, 2, port_str)) {
- // IPv6 addresses are wrapped in [] when specified with ports
- if (host_str.front() == '[' && host_str.back() == ']')
- host_str = host_str.substr(1, host_str.size() - 2);
- bool ok = false;
- port = StringConvert::ToUInt32(port_str.c_str(), UINT32_MAX, 10, &ok);
- if (ok && port <= UINT16_MAX) {
- if (error_ptr)
- error_ptr->Clear();
- return true;
- }
- // port is too large
+ llvm::SmallVector<llvm::StringRef, 3> matches;
+ if (g_regex.Execute(host_and_port, &matches)) {
+ host_str = matches[1].str();
+ port_str = matches[2].str();
+ // IPv6 addresses are wrapped in [] when specified with ports
+ if (host_str.front() == '[' && host_str.back() == ']')
+ host_str = host_str.substr(1, host_str.size() - 2);
+ bool ok = false;
+ port = StringConvert::ToUInt32(port_str.c_str(), UINT32_MAX, 10, &ok);
+ if (ok && port <= UINT16_MAX) {
if (error_ptr)
- error_ptr->SetErrorStringWithFormat(
- "invalid host:port specification: '%s'",
- host_and_port.str().c_str());
- return false;
+ error_ptr->Clear();
+ return true;
}
+ // port is too large
+ if (error_ptr)
+ error_ptr->SetErrorStringWithFormat(
+ "invalid host:port specification: '%s'", host_and_port.str().c_str());
+ return false;
}
// If this was unsuccessful, then check if it's simply a signed 32-bit
OpenPOWER on IntegriCloud