summaryrefslogtreecommitdiffstats
path: root/lldb/source/Utility/RegularExpression.cpp
blob: fd9d963f7294c22f064d1e2566b7c14d19dc3c17 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
//===-- 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)
    : m_regex_text(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();
}
OpenPOWER on IntegriCloud