class Regex

Declaration

class Regex { /* full declaration omitted */ };

Declared at: llvm/include/llvm/Support/Regex.h:28

Member Variables

private struct llvm_regex* preg
private int error

Method Overview

  • public Regex()
  • public Regex(llvm::StringRef Regex, llvm::Regex::RegexFlags Flags = NoFlags)
  • public Regex(llvm::StringRef Regex, unsigned int Flags)
  • public Regex(const llvm::Regex &)
  • public Regex(llvm::Regex && regex)
  • public static std::string escape(llvm::StringRef String)
  • public unsigned int getNumMatches() const
  • public static bool isLiteralERE(llvm::StringRef Str)
  • public bool isValid(std::string & Error) const
  • public bool isValid() const
  • public bool match(llvm::StringRef String, SmallVectorImpl<llvm::StringRef> * Matches = nullptr, std::string * Error = nullptr) const
  • public std::string sub(llvm::StringRef Repl, llvm::StringRef String, std::string * Error = nullptr) const
  • public ~Regex()

Methods

Regex()

Declared at: llvm/include/llvm/Support/Regex.h:48

Regex(llvm::StringRef Regex,
      llvm::Regex::RegexFlags Flags = NoFlags)

Description

Compiles the given regular expression \p Regex.

Declared at: llvm/include/llvm/Support/Regex.h:53

Parameters

llvm::StringRef Regex
- referenced string is no longer needed after this constructor does finish. Only its compiled form is kept stored.
llvm::Regex::RegexFlags Flags = NoFlags

Regex(llvm::StringRef Regex, unsigned int Flags)

Declared at: llvm/include/llvm/Support/Regex.h:54

Parameters

llvm::StringRef Regex
unsigned int Flags

Regex(const llvm::Regex&)

Declared at: llvm/include/llvm/Support/Regex.h:55

Parameters

const llvm::Regex&

Regex(llvm::Regex&& regex)

Declared at: llvm/include/llvm/Support/Regex.h:61

Parameters

llvm::Regex&& regex

static std::string escape(llvm::StringRef String)

Description

Turn String into a regex by escaping its special characters.

Declared at: llvm/include/llvm/Support/Regex.h:105

Parameters

llvm::StringRef String

unsigned int getNumMatches() const

Description

getNumMatches - In a valid regex, return the number of parenthesized matches it contains. The number filled in by match will include this many entries plus one for the whole regex (as element 0).

Declared at: llvm/include/llvm/Support/Regex.h:72

static bool isLiteralERE(llvm::StringRef Str)

Description

If this function returns true, ^Str$ is an extended regular expression that matches Str and only Str.

Declared at: llvm/include/llvm/Support/Regex.h:102

Parameters

llvm::StringRef Str

bool isValid(std::string& Error) const

Description

isValid - returns the error encountered during regex compilation, if any.

Declared at: llvm/include/llvm/Support/Regex.h:66

Parameters

std::string& Error

bool isValid() const

Declared at: llvm/include/llvm/Support/Regex.h:67

bool match(llvm::StringRef String,
           SmallVectorImpl<llvm::StringRef>*
               Matches = nullptr,
           std::string* Error = nullptr) const

Description

matches - Match the regex against a given \p String. This returns true on a successful match.

Declared at: llvm/include/llvm/Support/Regex.h:84

Parameters

llvm::StringRef String
SmallVectorImpl<llvm::StringRef>* Matches = nullptr
- If given, on a successful match this will be filled in with references to the matched group expressions (inside \p String), the first group is always the entire pattern.
std::string* Error = nullptr
- If non-null, any errors in the matching will be recorded as a non-empty string. If there is no error, it will be an empty string.

std::string sub(
    llvm::StringRef Repl,
    llvm::StringRef String,
    std::string* Error = nullptr) const

Description

sub - Return the result of replacing the first match of the regex in\p String with the \p Repl string. Backreferences like "\0" in the replacement string are replaced with the appropriate match substring. Note that the replacement string has backslash escaping performed on it. Invalid backreferences are ignored (replaced by empty strings).

Declared at: llvm/include/llvm/Support/Regex.h:97

Parameters

llvm::StringRef Repl
llvm::StringRef String
std::string* Error = nullptr
If non-null, any errors in the substitution (invalid backreferences, trailing backslashes) will be recorded as a non-empty string. If there is no error, it will be an empty string.

~Regex()

Declared at: llvm/include/llvm/Support/Regex.h:62