2010-06-09 00:52:24 +08:00
|
|
|
//===-- RegularExpression.cpp -----------------------------------*- C++ -*-===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// 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
|
2010-06-09 00:52:24 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2017-02-03 05:39:50 +08:00
|
|
|
#include "lldb/Utility/RegularExpression.h"
|
2016-03-12 08:31:13 +08:00
|
|
|
|
2017-04-07 02:12:24 +08:00
|
|
|
#include <string>
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2015-01-22 05:51:02 +08:00
|
|
|
using namespace lldb_private;
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2019-08-17 05:25:36 +08:00
|
|
|
RegularExpression::RegularExpression(llvm::StringRef str) { Compile(str); }
|
2011-09-21 09:17:13 +08:00
|
|
|
|
2019-05-24 04:11:17 +08:00
|
|
|
RegularExpression::RegularExpression(const RegularExpression &rhs)
|
|
|
|
: RegularExpression() {
|
2016-09-07 04:57:50 +08:00
|
|
|
Compile(rhs.GetText());
|
2011-09-21 09:17:13 +08:00
|
|
|
}
|
|
|
|
|
2016-09-22 00:01:28 +08:00
|
|
|
bool RegularExpression::Compile(llvm::StringRef str) {
|
2019-08-17 05:25:36 +08:00
|
|
|
m_regex_text = str;
|
|
|
|
m_regex = llvm::Regex(str);
|
|
|
|
return IsValid();
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2019-08-17 05:25:36 +08:00
|
|
|
bool RegularExpression::Execute(
|
|
|
|
llvm::StringRef str,
|
|
|
|
llvm::SmallVectorImpl<llvm::StringRef> *matches) const {
|
|
|
|
return m_regex.match(str, matches);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2014-10-23 05:43:15 +08:00
|
|
|
|
2019-08-17 05:25:36 +08:00
|
|
|
bool RegularExpression::IsValid() const {
|
|
|
|
std::string discarded;
|
|
|
|
return m_regex.isValid(discarded);
|
2013-01-30 08:18:29 +08:00
|
|
|
}
|
|
|
|
|
2019-08-17 05:25:36 +08:00
|
|
|
llvm::StringRef RegularExpression::GetText() const { return m_regex_text; }
|
2010-10-11 07:55:27 +08:00
|
|
|
|
2019-08-17 05:25:36 +08:00
|
|
|
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();
|
2011-07-02 08:25:22 +08:00
|
|
|
}
|