1*0b57cec5SDimitry Andric //===-- RegularExpression.cpp ---------------------------------------------===// 2*0b57cec5SDimitry Andric // 3*0b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4*0b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 5*0b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6*0b57cec5SDimitry Andric // 7*0b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 8*0b57cec5SDimitry Andric 9*0b57cec5SDimitry Andric #include "lldb/Utility/RegularExpression.h" 10*0b57cec5SDimitry Andric 11*0b57cec5SDimitry Andric #include <string> 12*0b57cec5SDimitry Andric 13*0b57cec5SDimitry Andric using namespace lldb_private; 14*0b57cec5SDimitry Andric RegularExpression(llvm::StringRef str)15*0b57cec5SDimitry AndricRegularExpression::RegularExpression(llvm::StringRef str) 16*0b57cec5SDimitry Andric : m_regex_text(std::string(str)), 17*0b57cec5SDimitry Andric // m_regex does not reference str anymore after it is constructed. 18*0b57cec5SDimitry Andric m_regex(llvm::Regex(str)) {} 19*0b57cec5SDimitry Andric RegularExpression(const RegularExpression & rhs)20*0b57cec5SDimitry AndricRegularExpression::RegularExpression(const RegularExpression &rhs) 21*0b57cec5SDimitry Andric : RegularExpression(rhs.GetText()) {} 22*0b57cec5SDimitry Andric Execute(llvm::StringRef str,llvm::SmallVectorImpl<llvm::StringRef> * matches) const23*0b57cec5SDimitry Andricbool RegularExpression::Execute( 24*0b57cec5SDimitry Andric llvm::StringRef str, 25*0b57cec5SDimitry Andric llvm::SmallVectorImpl<llvm::StringRef> *matches) const { 26*0b57cec5SDimitry Andric if (!IsValid()) 27*0b57cec5SDimitry Andric return false; 28*0b57cec5SDimitry Andric return m_regex.match(str, matches); 29*0b57cec5SDimitry Andric } 30*0b57cec5SDimitry Andric IsValid() const31*0b57cec5SDimitry Andricbool RegularExpression::IsValid() const { return m_regex.isValid(); } 32*0b57cec5SDimitry Andric GetText() const33*0b57cec5SDimitry Andricllvm::StringRef RegularExpression::GetText() const { return m_regex_text; } 34*0b57cec5SDimitry Andric GetError() const35*0b57cec5SDimitry Andricllvm::Error RegularExpression::GetError() const { 36*0b57cec5SDimitry Andric std::string error; 37*0b57cec5SDimitry Andric if (!m_regex.isValid(error)) 38*0b57cec5SDimitry Andric return llvm::make_error<llvm::StringError>(error, 39*0b57cec5SDimitry Andric llvm::inconvertibleErrorCode()); 40*0b57cec5SDimitry Andric return llvm::Error::success(); 41*0b57cec5SDimitry Andric } 42*0b57cec5SDimitry Andric