Files
clang-p2996/lldb/source/Utility/RegularExpression.cpp
Jonas Devlieghere 3af3f1e8e2 [Utility] Reimplement RegularExpression on top of llvm::Regex
Originally I wanted to remove the RegularExpression class in Utility and
replace it with llvm::Regex. However, during that transition I noticed
that there are several places where need the regular expression string.
So instead I propose to keep the RegularExpression class and make it a
thin wrapper around llvm::Regex.

This patch also removes the workaround for empty regular expressions.
The result is that we are now (more or less) POSIX conformant.

Differential revision: https://reviews.llvm.org/D66174

llvm-svn: 369153
2019-08-16 21:25:36 +00:00

48 lines
1.4 KiB
C++

//===-- RegularExpression.cpp -----------------------------------*- C++ -*-===//
//
// 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) { Compile(str); }
RegularExpression::RegularExpression(const RegularExpression &rhs)
: RegularExpression() {
Compile(rhs.GetText());
}
bool RegularExpression::Compile(llvm::StringRef str) {
m_regex_text = str;
m_regex = llvm::Regex(str);
return IsValid();
}
bool RegularExpression::Execute(
llvm::StringRef str,
llvm::SmallVectorImpl<llvm::StringRef> *matches) const {
return m_regex.match(str, matches);
}
bool RegularExpression::IsValid() const {
std::string discarded;
return m_regex.isValid(discarded);
}
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();
}