[Lldb-commits] [PATCH] D66174: [Utility] Phase out RegularExpression and use llvm::Regex instead.

Jonas Devlieghere via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Tue Aug 13 14:48:56 PDT 2019


JDevlieghere created this revision.
JDevlieghere added a reviewer: LLDB.
JDevlieghere added a project: LLDB.
Herald added a subscriber: abidh.

I want to remove the RegularExpression class in Utility and replace it with llvm::Regex.

This is something I'd do incrementally on the side when I have some spare minutes. This patch is to make sure everybody is on board and show what the interface looks like.


Repository:
  rLLDB LLDB

https://reviews.llvm.org/D66174

Files:
  lldb/source/Host/common/Socket.cpp
  lldb/source/Utility/FileSpec.cpp


Index: lldb/source/Utility/FileSpec.cpp
===================================================================
--- lldb/source/Utility/FileSpec.cpp
+++ lldb/source/Utility/FileSpec.cpp
@@ -7,7 +7,6 @@
 //===----------------------------------------------------------------------===//
 
 #include "lldb/Utility/FileSpec.h"
-#include "lldb/Utility/RegularExpression.h"
 #include "lldb/Utility/Stream.h"
 
 #include "llvm/ADT/SmallString.h"
@@ -18,6 +17,7 @@
 #include "llvm/Support/ErrorOr.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Program.h"
+#include "llvm/Support/Regex.h"
 #include "llvm/Support/raw_ostream.h"
 
 #include <algorithm>
@@ -487,12 +487,12 @@
   if (!extension)
     return false;
 
-  static RegularExpression g_source_file_regex(llvm::StringRef(
+  static llvm::Regex g_source_file_regex(
       "^.([cC]|[mM]|[mM][mM]|[cC][pP][pP]|[cC]\\+\\+|[cC][xX][xX]|[cC][cC]|["
       "cC][pP]|[sS]|[aA][sS][mM]|[fF]|[fF]77|[fF]90|[fF]95|[fF]03|[fF][oO]["
       "rR]|[fF][tT][nN]|[fF][pP][pP]|[aA][dD][aA]|[aA][dD][bB]|[aA][dD][sS])"
-      "$"));
-  return g_source_file_regex.Execute(extension.GetStringRef());
+      "$");
+  return g_source_file_regex.match(extension.GetStringRef());
 }
 
 bool FileSpec::IsRelative() const {
Index: lldb/source/Host/common/Socket.cpp
===================================================================
--- lldb/source/Host/common/Socket.cpp
+++ lldb/source/Host/common/Socket.cpp
@@ -15,11 +15,11 @@
 #include "lldb/Host/common/TCPSocket.h"
 #include "lldb/Host/common/UDPSocket.h"
 #include "lldb/Utility/Log.h"
-#include "lldb/Utility/RegularExpression.h"
 
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/Support/Errno.h"
 #include "llvm/Support/Error.h"
+#include "llvm/Support/Regex.h"
 #include "llvm/Support/WindowsError.h"
 
 #ifndef LLDB_DISABLE_POSIX
@@ -280,12 +280,12 @@
 bool Socket::DecodeHostAndPort(llvm::StringRef host_and_port,
                                std::string &host_str, std::string &port_str,
                                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)) {
+  static llvm::Regex g_regex("([^:]+|\\[[0-9a-fA-F:]+.*\\]):([0-9]+)");
+  llvm::SmallVector<llvm::StringRef, 3> matches;
+  if (g_regex.match(host_and_port, &matches)) {
+    if (matches.size() == 3) {
+      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);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D66174.214930.patch
Type: text/x-patch
Size: 2867 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20190813/14704777/attachment.bin>


More information about the lldb-commits mailing list