Files
clang-p2996/lldb/source/Utility/RegularExpression.cpp
Benjamin Kramer adcd026838 Make llvm::StringRef to std::string conversions explicit.
This is how it should've been and brings it more in line with
std::string_view. There should be no functional change here.

This is mostly mechanical from a custom clang-tidy check, with a lot of
manual fixups. It uncovers a lot of minor inefficiencies.

This doesn't actually modify StringRef yet, I'll do that in a follow-up.
2020-01-28 23:25:25 +01:00

42 lines
1.4 KiB
C++

//===-- 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
//
//===----------------------------------------------------------------------===//
#include "lldb/Utility/RegularExpression.h"
#include <string>
using namespace lldb_private;
RegularExpression::RegularExpression(llvm::StringRef str)
: m_regex_text(std::string(str)),
// m_regex does not reference str anymore after it is constructed.
m_regex(llvm::Regex(str)) {}
RegularExpression::RegularExpression(const RegularExpression &rhs)
: RegularExpression(rhs.GetText()) {}
bool RegularExpression::Execute(
llvm::StringRef str,
llvm::SmallVectorImpl<llvm::StringRef> *matches) const {
if (!IsValid())
return false;
return m_regex.match(str, matches);
}
bool RegularExpression::IsValid() const { return m_regex.isValid(); }
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>(llvm::inconvertibleErrorCode(),
error);
return llvm::Error::success();
}