LLVM  10.0.0svn
Public Types | Public Member Functions | Static Public Member Functions | List of all members
llvm::Regex Class Reference

#include "llvm/Support/Regex.h"

Public Types

enum  { NoFlags =0, IgnoreCase =1, Newline =2, BasicRegex =4 }
 

Public Member Functions

 Regex ()
 
 Regex (StringRef Regex, unsigned Flags=NoFlags)
 Compiles the given regular expression Regex. More...
 
 Regex (const Regex &)=delete
 
Regexoperator= (Regex regex)
 
 Regex (Regex &&regex)
 
 ~Regex ()
 
bool isValid (std::string &Error) const
 isValid - returns the error encountered during regex compilation, if any. More...
 
bool isValid () const
 
unsigned getNumMatches () const
 getNumMatches - In a valid regex, return the number of parenthesized matches it contains. More...
 
bool match (StringRef String, SmallVectorImpl< StringRef > *Matches=nullptr, std::string *Error=nullptr) const
 matches - Match the regex against a given String. More...
 
std::string sub (StringRef Repl, StringRef String, std::string *Error=nullptr) const
 sub - Return the result of replacing the first match of the regex in String with the Repl string. More...
 

Static Public Member Functions

static bool isLiteralERE (StringRef Str)
 If this function returns true, ^Str$ is an extended regular expression that matches Str and only Str. More...
 
static std::string escape (StringRef String)
 Turn String into a regex by escaping its special characters. More...
 

Detailed Description

Definition at line 27 of file Regex.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
Enumerator
NoFlags 
IgnoreCase 

Compile for matching that ignores upper/lower case distinctions.

Newline 

Compile for newline-sensitive matching.

With this flag '[^' bracket expressions and '.' never match newline. A ^ anchor matches the null string after any newline in the string in addition to its normal function, and the $ anchor matches the null string before any newline in the string in addition to its normal function.

BasicRegex 

By default, the POSIX extended regular expression (ERE) syntax is assumed.

Pass this flag to turn on basic regular expressions (BRE) instead.

Definition at line 29 of file Regex.h.

Constructor & Destructor Documentation

◆ Regex() [1/4]

Regex::Regex ( )

Definition at line 26 of file Regex.cpp.

Referenced by operator=().

◆ Regex() [2/4]

Regex::Regex ( StringRef  Regex,
unsigned  Flags = NoFlags 
)

Compiles the given regular expression Regex.

Parameters
Regex- referenced string is no longer needed after this constructor does finish. Only its compiled form is kept stored.

Definition at line 28 of file Regex.cpp.

References BasicRegex, llvm::StringRef::data(), llvm::StringRef::end(), error, IgnoreCase, llvm_regcomp(), Newline, llvm_regex::re_endp, REG_EXTENDED, REG_ICASE, REG_NEWLINE, and REG_PEND.

◆ Regex() [3/4]

llvm::Regex::Regex ( const Regex )
delete

◆ Regex() [4/4]

Regex::Regex ( Regex &&  regex)

Definition at line 41 of file Regex.cpp.

References error, and REG_BADPAT.

◆ ~Regex()

Regex::~Regex ( )

Definition at line 48 of file Regex.cpp.

References error, llvm_regerror(), and llvm_regfree().

Referenced by operator=().

Member Function Documentation

◆ escape()

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

Turn String into a regex by escaping its special characters.

Definition at line 215 of file Regex.cpp.

References llvm::numbers::e, and llvm::StringRef::size().

Referenced by llvm::FileCheckStringSubstitution::getResult(), and isValid().

◆ getNumMatches()

unsigned Regex::getNumMatches ( ) const

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).

Definition at line 78 of file Regex.cpp.

Referenced by isValid().

◆ isLiteralERE()

bool Regex::isLiteralERE ( StringRef  Str)
static

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

Definition at line 208 of file Regex.cpp.

References llvm::StringRef::find_first_of(), and llvm::StringRef::npos.

Referenced by llvm::SpecialCaseList::Matcher::insert(), and isValid().

◆ isValid() [1/2]

bool Regex::isValid ( std::string &  Error) const

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

Definition at line 68 of file Regex.cpp.

References error.

Referenced by llvm::SpecialCaseList::Matcher::insert(), llvm::SpecialCaseList::parse(), and llvm::RemarkStreamer::setFilter().

◆ isValid() [2/2]

bool llvm::Regex::isValid ( ) const
inline

Definition at line 63 of file Regex.h.

References error, escape(), getNumMatches(), isLiteralERE(), match(), llvm::String, and sub().

Referenced by match(), and operator=().

◆ match()

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

matches - Match the regex against a given String.

Parameters
Matches- If given, on a successful match this will be filled in with references to the matched group expressions (inside String), the first group is always the entire pattern.
Error- 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.

This returns true on a successful match.

Definition at line 82 of file Regex.cpp.

References assert(), llvm::SmallVectorImpl< T >::clear(), llvm::StringRef::data(), llvm::SmallVectorTemplateCommon< T >::data(), error, isValid(), llvm_regexec(), adjust::pm(), llvm::SmallVectorTemplateBase< T, bool >::push_back(), rc, REG_NOMATCH, REG_STARTEND, llvm::SmallVectorImpl< T >::resize(), and llvm::StringRef::size().

Referenced by FindFirstMatchingPrefix(), isModulePassName(), isValid(), llvm::AArch64SysReg::parseGenericRegister(), sub(), llvm::UpgradeDataLayoutString(), UpgradeIntrinsicFunction1(), and ValidateCheckPrefix().

◆ operator=()

Regex& llvm::Regex::operator= ( Regex  regex)
inline

Definition at line 52 of file Regex.h.

References isValid(), Regex(), std::swap(), and ~Regex().

◆ sub()

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

sub - Return the result of replacing the first match of the regex in String with the 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).

Parameters
ErrorIf 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.

Definition at line 132 of file Regex.cpp.

References llvm::StringRef::begin(), llvm::SmallVectorTemplateCommon< T >::begin(), llvm::StringRef::empty(), llvm::sys::path::end(), llvm::StringRef::end(), llvm::SmallVectorTemplateCommon< T >::end(), llvm::StringRef::find_first_not_of(), llvm::StringRef::getAsInteger(), match(), llvm::Ref, llvm::SmallVectorBase::size(), llvm::StringRef::size(), llvm::StringRef::slice(), llvm::StringRef::split(), llvm::String, and llvm::StringRef::substr().

Referenced by isValid(), and rewriteComdat().


The documentation for this class was generated from the following files: