[Lldb-commits] [lldb] r220431 - Re-use the GetMatchAtIndex() that uses the StringRef to avoid code duplication and properly detect when a capture is invalid and return false.

Greg Clayton gclayton at apple.com
Wed Oct 22 14:43:15 PDT 2014


Author: gclayton
Date: Wed Oct 22 16:43:15 2014
New Revision: 220431

URL: http://llvm.org/viewvc/llvm-project?rev=220431&view=rev
Log:
Re-use the GetMatchAtIndex() that uses the StringRef to avoid code duplication and properly detect when a capture is invalid and return false.


Modified:
    lldb/trunk/source/Core/RegularExpression.cpp

Modified: lldb/trunk/source/Core/RegularExpression.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/RegularExpression.cpp?rev=220431&r1=220430&r2=220431&view=diff
==============================================================================
--- lldb/trunk/source/Core/RegularExpression.cpp (original)
+++ lldb/trunk/source/Core/RegularExpression.cpp Wed Oct 22 16:43:15 2014
@@ -162,20 +162,11 @@ RegularExpression::Execute(const char* s
 bool
 RegularExpression::Match::GetMatchAtIndex (const char* s, uint32_t idx, std::string& match_str) const
 {
-    if (idx < m_matches.size())
+    llvm::StringRef match_str_ref;
+    if (GetMatchAtIndex(s, idx, match_str_ref))
     {
-        if (m_matches[idx].rm_eo == m_matches[idx].rm_so)
-        {
-            // Matched the empty string...
-            match_str.clear();
-            return true;
-        }
-        else if (m_matches[idx].rm_eo > m_matches[idx].rm_so)
-        {
-            match_str.assign (s + m_matches[idx].rm_so,
-                              m_matches[idx].rm_eo - m_matches[idx].rm_so);
-            return true;
-        }
+        match_str = std::move(match_str_ref.str());
+        return true;
     }
     return false;
 }
@@ -185,6 +176,9 @@ RegularExpression::Match::GetMatchAtInde
 {
     if (idx < m_matches.size())
     {
+        if (m_matches[idx].rm_eo == -1 && m_matches[idx].rm_so == -1)
+            return false;
+
         if (m_matches[idx].rm_eo == m_matches[idx].rm_so)
         {
             // Matched the empty string...





More information about the lldb-commits mailing list