Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:42:58

0001 //===-- RegularExpression.h -------------------------------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef LLDB_UTILITY_REGULAREXPRESSION_H
0010 #define LLDB_UTILITY_REGULAREXPRESSION_H
0011 
0012 #include "llvm/ADT/StringRef.h"
0013 #include "llvm/Support/Error.h"
0014 #include "llvm/Support/Regex.h"
0015 
0016 namespace lldb_private {
0017 
0018 class RegularExpression {
0019 public:
0020   /// The default constructor that initializes the object state such that it
0021   /// contains no compiled regular expression.
0022   RegularExpression() = default;
0023 
0024   /// Constructor for a regular expression.
0025   ///
0026   /// Compile a regular expression using the supplied regular expression text.
0027   /// The compiled regular expression lives in this object so that it can be
0028   /// readily used for regular expression matches. Execute() can be called
0029   /// after the regular expression is compiled.
0030   ///
0031   /// \param[in] string
0032   ///     An llvm::StringRef that represents the regular expression to compile.
0033   //      String is not referenced anymore after the object is constructed.
0034   //
0035   /// \param[in] flags
0036   ///     An llvm::Regex::RegexFlags that modifies the matching behavior. The
0037   ///     default is NoFlags.
0038   explicit RegularExpression(
0039       llvm::StringRef string,
0040       llvm::Regex::RegexFlags flags = llvm::Regex::NoFlags);
0041 
0042   ~RegularExpression() = default;
0043 
0044   RegularExpression(const RegularExpression &rhs);
0045   RegularExpression(RegularExpression &&rhs) = default;
0046 
0047   RegularExpression &operator=(RegularExpression &&rhs) = default;
0048   RegularExpression &operator=(const RegularExpression &rhs) = default;
0049 
0050   /// Execute a regular expression match using the compiled regular expression
0051   /// that is already in this object against the given \a string. If any parens
0052   /// are used for regular expression matches.
0053   ///
0054   /// \param[in] string
0055   ///     The string to match against the compile regular expression.
0056   ///
0057   /// \param[out] matches
0058   ///     A pointer to a SmallVector to hold the matches.
0059   ///
0060   /// \return
0061   ///     true if \a string matches the compiled regular expression, false
0062   ///     otherwise incl. the case regular exression failed to compile.
0063   bool Execute(llvm::StringRef string,
0064                llvm::SmallVectorImpl<llvm::StringRef> *matches = nullptr) const;
0065 
0066   /// Access the regular expression text.
0067   ///
0068   /// \return
0069   ///     The NULL terminated C string that was used to compile the
0070   ///     current regular expression
0071   llvm::StringRef GetText() const;
0072 
0073   /// Test if this object contains a valid regular expression.
0074   ///
0075   /// \return
0076   ///     true if the regular expression compiled and is ready for execution,
0077   ///     false otherwise.
0078   bool IsValid() const;
0079 
0080   /// Return an error if the regular expression failed to compile.
0081   ///
0082   /// \return
0083   ///     A string error if the regular expression failed to compile, success
0084   ///     otherwise.
0085   llvm::Error GetError() const;
0086 
0087   bool operator==(const RegularExpression &rhs) const {
0088     return GetText() == rhs.GetText();
0089   }
0090 
0091 private:
0092   /// A copy of the original regular expression text.
0093   std::string m_regex_text;
0094   /// The compiled regular expression.
0095   mutable llvm::Regex m_regex;
0096 };
0097 
0098 } // namespace lldb_private
0099 
0100 #endif // LLDB_UTILITY_REGULAREXPRESSION_H