1cfca06d7SDimitry Andric //===-- RegularExpression.cpp ---------------------------------------------===// 2f034231aSEd Maste // 35f29bb8aSDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 45f29bb8aSDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 55f29bb8aSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6f034231aSEd Maste // 7f034231aSEd Maste //===----------------------------------------------------------------------===// 8f034231aSEd Maste 974a628f7SDimitry Andric #include "lldb/Utility/RegularExpression.h" 1012bd4897SEd Maste 1174a628f7SDimitry Andric #include <string> 1212bd4897SEd Maste 13f034231aSEd Maste using namespace lldb_private; 14f034231aSEd Maste RegularExpression(llvm::StringRef str,llvm::Regex::RegexFlags flags)15ac9a064cSDimitry AndricRegularExpression::RegularExpression(llvm::StringRef str, 16ac9a064cSDimitry Andric llvm::Regex::RegexFlags flags) 17cfca06d7SDimitry Andric : m_regex_text(std::string(str)), 18ead24645SDimitry Andric // m_regex does not reference str anymore after it is constructed. 19ac9a064cSDimitry Andric m_regex(llvm::Regex(str, flags)) {} 20f034231aSEd Maste RegularExpression(const RegularExpression & rhs)215f29bb8aSDimitry AndricRegularExpression::RegularExpression(const RegularExpression &rhs) 22ead24645SDimitry Andric : RegularExpression(rhs.GetText()) {} 23f034231aSEd Maste Execute(llvm::StringRef str,llvm::SmallVectorImpl<llvm::StringRef> * matches) const24ead24645SDimitry Andricbool RegularExpression::Execute( 25ead24645SDimitry Andric llvm::StringRef str, 26ead24645SDimitry Andric llvm::SmallVectorImpl<llvm::StringRef> *matches) const { 27ead24645SDimitry Andric if (!IsValid()) 28f034231aSEd Maste return false; 29ead24645SDimitry Andric return m_regex.match(str, matches); 30f034231aSEd Maste } 31f034231aSEd Maste IsValid() const32ead24645SDimitry Andricbool RegularExpression::IsValid() const { return m_regex.isValid(); } 33f034231aSEd Maste GetText() const34ead24645SDimitry Andricllvm::StringRef RegularExpression::GetText() const { return m_regex_text; } 35205afe67SEd Maste GetError() const36ead24645SDimitry Andricllvm::Error RegularExpression::GetError() const { 37ead24645SDimitry Andric std::string error; 38ead24645SDimitry Andric if (!m_regex.isValid(error)) 39cfca06d7SDimitry Andric return llvm::make_error<llvm::StringError>(error, 40cfca06d7SDimitry Andric llvm::inconvertibleErrorCode()); 41ead24645SDimitry Andric return llvm::Error::success(); 42f034231aSEd Maste } 43