180814287SRaphael Isemann //===-- RegularExpression.cpp ---------------------------------------------===// 2bf9a7730SZachary Turner // 32946cd70SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 42946cd70SChandler Carruth // See https://llvm.org/LICENSE.txt for license information. 52946cd70SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6bf9a7730SZachary Turner // 7bf9a7730SZachary Turner //===----------------------------------------------------------------------===// 8bf9a7730SZachary Turner 9bf9a7730SZachary Turner #include "lldb/Utility/RegularExpression.h" 10bf9a7730SZachary Turner 114479ac15SZachary Turner #include <string> 12bf9a7730SZachary Turner 13bf9a7730SZachary Turner using namespace lldb_private; 14bf9a7730SZachary Turner RegularExpression(llvm::StringRef str)15f9d90bc5SJan KratochvilRegularExpression::RegularExpression(llvm::StringRef str) 16adcd0268SBenjamin Kramer : m_regex_text(std::string(str)), 17f9d90bc5SJan Kratochvil // m_regex does not reference str anymore after it is constructed. 18f9d90bc5SJan Kratochvil m_regex(llvm::Regex(str)) {} 19bf9a7730SZachary Turner RegularExpression(const RegularExpression & rhs)2056d69ef8SJorge Gorbe MoyaRegularExpression::RegularExpression(const RegularExpression &rhs) 21f9d90bc5SJan Kratochvil : RegularExpression(rhs.GetText()) {} 22bf9a7730SZachary Turner Execute(llvm::StringRef str,llvm::SmallVectorImpl<llvm::StringRef> * matches) const233af3f1e8SJonas Devliegherebool RegularExpression::Execute( 243af3f1e8SJonas Devlieghere llvm::StringRef str, 253af3f1e8SJonas Devlieghere llvm::SmallVectorImpl<llvm::StringRef> *matches) const { 26f9d90bc5SJan Kratochvil if (!IsValid()) 27f9d90bc5SJan Kratochvil return false; 283af3f1e8SJonas Devlieghere return m_regex.match(str, matches); 29bf9a7730SZachary Turner } 30bf9a7730SZachary Turner IsValid() const311c56d3dfSJan Kratochvilbool RegularExpression::IsValid() const { return m_regex.isValid(); } 32bf9a7730SZachary Turner GetText() const333af3f1e8SJonas Devliegherellvm::StringRef RegularExpression::GetText() const { return m_regex_text; } 34bf9a7730SZachary Turner GetError() const353af3f1e8SJonas Devliegherellvm::Error RegularExpression::GetError() const { 363af3f1e8SJonas Devlieghere std::string error; 373af3f1e8SJonas Devlieghere if (!m_regex.isValid(error)) 38*b58af8d2SRaphael Isemann return llvm::make_error<llvm::StringError>(error, 39*b58af8d2SRaphael Isemann llvm::inconvertibleErrorCode()); 403af3f1e8SJonas Devlieghere return llvm::Error::success(); 41bf9a7730SZachary Turner } 42