Files

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

42 lines
1.4 KiB
C++
Raw Permalink Normal View History

//===-- RegularExpression.cpp ---------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
2017-02-02 21:39:50 +00:00
#include "lldb/Utility/RegularExpression.h"
2017-04-06 18:12:24 +00:00
#include <string>
using namespace lldb_private;
2019-08-20 09:24:20 +00:00
RegularExpression::RegularExpression(llvm::StringRef str)
: m_regex_text(std::string(str)),
2019-08-20 09:24:20 +00:00
// m_regex does not reference str anymore after it is constructed.
m_regex(llvm::Regex(str)) {}
RegularExpression::RegularExpression(const RegularExpression &rhs)
2019-08-20 09:24:20 +00:00
: RegularExpression(rhs.GetText()) {}
bool RegularExpression::Execute(
llvm::StringRef str,
llvm::SmallVectorImpl<llvm::StringRef> *matches) const {
2019-08-20 09:24:20 +00:00
if (!IsValid())
return false;
return m_regex.match(str, matches);
}
bool RegularExpression::IsValid() const { return m_regex.isValid(); }
2013-01-30 00:18:29 +00:00
llvm::StringRef RegularExpression::GetText() const { return m_regex_text; }
llvm::Error RegularExpression::GetError() const {
std::string error;
if (!m_regex.isValid(error))
return llvm::make_error<llvm::StringError>(error,
llvm::inconvertibleErrorCode());
return llvm::Error::success();
2011-07-02 00:25:22 +00:00
}