Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / lldb / source / Utility / RegularExpression.cpp
blob20bebbfe15f27051236bcfef8fb690faeb74a0c2
1 //===-- RegularExpression.cpp ---------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #include "lldb/Utility/RegularExpression.h"
11 #include <string>
13 using namespace lldb_private;
15 RegularExpression::RegularExpression(llvm::StringRef str)
16 : m_regex_text(std::string(str)),
17 // m_regex does not reference str anymore after it is constructed.
18 m_regex(llvm::Regex(str)) {}
20 RegularExpression::RegularExpression(const RegularExpression &rhs)
21 : RegularExpression(rhs.GetText()) {}
23 bool RegularExpression::Execute(
24 llvm::StringRef str,
25 llvm::SmallVectorImpl<llvm::StringRef> *matches) const {
26 if (!IsValid())
27 return false;
28 return m_regex.match(str, matches);
31 bool RegularExpression::IsValid() const { return m_regex.isValid(); }
33 llvm::StringRef RegularExpression::GetText() const { return m_regex_text; }
35 llvm::Error RegularExpression::GetError() const {
36 std::string error;
37 if (!m_regex.isValid(error))
38 return llvm::make_error<llvm::StringError>(error,
39 llvm::inconvertibleErrorCode());
40 return llvm::Error::success();