Path: blob/main/contrib/llvm-project/lldb/source/Utility/RegularExpression.cpp
39587 views
//===-- RegularExpression.cpp ---------------------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#include "lldb/Utility/RegularExpression.h"910#include <string>1112using namespace lldb_private;1314RegularExpression::RegularExpression(llvm::StringRef str,15llvm::Regex::RegexFlags flags)16: m_regex_text(std::string(str)),17// m_regex does not reference str anymore after it is constructed.18m_regex(llvm::Regex(str, flags)) {}1920RegularExpression::RegularExpression(const RegularExpression &rhs)21: RegularExpression(rhs.GetText()) {}2223bool RegularExpression::Execute(24llvm::StringRef str,25llvm::SmallVectorImpl<llvm::StringRef> *matches) const {26if (!IsValid())27return false;28return m_regex.match(str, matches);29}3031bool RegularExpression::IsValid() const { return m_regex.isValid(); }3233llvm::StringRef RegularExpression::GetText() const { return m_regex_text; }3435llvm::Error RegularExpression::GetError() const {36std::string error;37if (!m_regex.isValid(error))38return llvm::make_error<llvm::StringError>(error,39llvm::inconvertibleErrorCode());40return llvm::Error::success();41}424344