summaryrefslogtreecommitdiffstats
path: root/lldb/source/Core/RegularExpression.cpp
diff options
context:
space:
mode:
authorGreg Clayton <gclayton@apple.com>2014-10-22 21:43:15 +0000
committerGreg Clayton <gclayton@apple.com>2014-10-22 21:43:15 +0000
commitfa226b74d18ff910fe069377fec7d05ee1c61975 (patch)
tree0678de5c4504ff28e9b4497760384be2b17692ea /lldb/source/Core/RegularExpression.cpp
parentb5c4971a4c5c285350b310ad81871d5db7a941f6 (diff)
downloadbcm5719-llvm-fa226b74d18ff910fe069377fec7d05ee1c61975.tar.gz
bcm5719-llvm-fa226b74d18ff910fe069377fec7d05ee1c61975.zip
Re-use the GetMatchAtIndex() that uses the StringRef to avoid code duplication and properly detect when a capture is invalid and return false.
llvm-svn: 220431
Diffstat (limited to 'lldb/source/Core/RegularExpression.cpp')
-rw-r--r--lldb/source/Core/RegularExpression.cpp20
1 files changed, 7 insertions, 13 deletions
diff --git a/lldb/source/Core/RegularExpression.cpp b/lldb/source/Core/RegularExpression.cpp
index 88415f61682..54924d06953 100644
--- a/lldb/source/Core/RegularExpression.cpp
+++ b/lldb/source/Core/RegularExpression.cpp
@@ -162,20 +162,11 @@ RegularExpression::Execute(const char* s, Match *match, int execute_flags) const
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::GetMatchAtIndex (const char* s, uint32_t idx, llvm::St
{
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...
OpenPOWER on IntegriCloud