LLDB mainline
RegularExpression.h
Go to the documentation of this file.
1//===-- RegularExpression.h -------------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLDB_UTILITY_REGULAREXPRESSION_H
10#define LLDB_UTILITY_REGULAREXPRESSION_H
11
12#include "llvm/ADT/StringRef.h"
13#include "llvm/Support/Error.h"
14#include "llvm/Support/Regex.h"
15
16namespace lldb_private {
17
19public:
20 /// The default constructor that initializes the object state such that it
21 /// contains no compiled regular expression.
22 RegularExpression() = default;
23
24 /// Constructor for a regular expression.
25 ///
26 /// Compile a regular expression using the supplied regular expression text.
27 /// The compiled regular expression lives in this object so that it can be
28 /// readily used for regular expression matches. Execute() can be called
29 /// after the regular expression is compiled.
30 ///
31 /// \param[in] string
32 /// An llvm::StringRef that represents the regular expression to compile.
33 // String is not referenced anymore after the object is constructed.
34 explicit RegularExpression(llvm::StringRef string);
35
36 ~RegularExpression() = default;
37
40
43
44 /// Execute a regular expression match using the compiled regular expression
45 /// that is already in this object against the given \a string. If any parens
46 /// are used for regular expression matches.
47 ///
48 /// \param[in] string
49 /// The string to match against the compile regular expression.
50 ///
51 /// \param[out] matches
52 /// A pointer to a SmallVector to hold the matches.
53 ///
54 /// \return
55 /// true if \a string matches the compiled regular expression, false
56 /// otherwise incl. the case regular exression failed to compile.
57 bool Execute(llvm::StringRef string,
58 llvm::SmallVectorImpl<llvm::StringRef> *matches = nullptr) const;
59
60 /// Access the regular expression text.
61 ///
62 /// \return
63 /// The NULL terminated C string that was used to compile the
64 /// current regular expression
65 llvm::StringRef GetText() const;
66
67 /// Test if this object contains a valid regular expression.
68 ///
69 /// \return
70 /// true if the regular expression compiled and is ready for execution,
71 /// false otherwise.
72 bool IsValid() const;
73
74 /// Return an error if the regular expression failed to compile.
75 ///
76 /// \return
77 /// A string error if the regular expression failed to compile, success
78 /// otherwise.
79 llvm::Error GetError() const;
80
81 bool operator==(const RegularExpression &rhs) const {
82 return GetText() == rhs.GetText();
83 }
84
85private:
86 /// A copy of the original regular expression text.
87 std::string m_regex_text;
88 /// The compiled regular expression.
89 mutable llvm::Regex m_regex;
90};
91
92} // namespace lldb_private
93
94#endif // LLDB_UTILITY_REGULAREXPRESSION_H
RegularExpression & operator=(RegularExpression &&rhs)=default
std::string m_regex_text
A copy of the original regular expression text.
bool IsValid() const
Test if this object contains a valid regular expression.
bool Execute(llvm::StringRef string, llvm::SmallVectorImpl< llvm::StringRef > *matches=nullptr) const
Execute a regular expression match using the compiled regular expression that is already in this obje...
llvm::Error GetError() const
Return an error if the regular expression failed to compile.
llvm::Regex m_regex
The compiled regular expression.
llvm::StringRef GetText() const
Access the regular expression text.
RegularExpression(RegularExpression &&rhs)=default
RegularExpression()=default
The default constructor that initializes the object state such that it contains no compiled regular e...
RegularExpression & operator=(const RegularExpression &rhs)=default
bool operator==(const RegularExpression &rhs) const
A class that represents a running process on the host machine.
Definition: SBAttachInfo.h:14