LLVM
8.0.1
|
#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 | |
Regex & | operator= (Regex regex) |
Regex (Regex &®ex) | |
~Regex () | |
bool | isValid (std::string &Error) const |
isValid - returns the error encountered during regex compilation, or matching, if any. More... | |
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) |
matches - Match the regex against a given String . More... | |
std::string | sub (StringRef Repl, StringRef String, std::string *Error=nullptr) |
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... | |
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. |
Regex::Regex | ( | ) |
Definition at line 27 of file Regex.cpp.
Referenced by operator=().
Compiles the given regular expression Regex
.
Definition at line 29 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::Regex | ( | Regex && | regex | ) |
Definition at line 42 of file Regex.cpp.
References error, and REG_BADPAT.
Regex::~Regex | ( | ) |
|
static |
Turn String into a regex by escaping its special characters.
Definition at line 201 of file Regex.cpp.
References llvm::StringRef::size().
Referenced by llvm::FileCheckPattern::Match(), and operator=().
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 69 of file Regex.cpp.
References llvm_regex::re_nsub.
Referenced by operator=().
If this function returns true, ^Str$ is an extended regular expression that matches Str and only Str.
Definition at line 194 of file Regex.cpp.
References llvm::StringRef::find_first_of(), and llvm::StringRef::npos.
Referenced by llvm::SpecialCaseList::Matcher::insert(), and operator=().
bool Regex::isValid | ( | std::string & | Error | ) | const |
isValid - returns the error encountered during regex compilation, or matching, if any.
Definition at line 56 of file Regex.cpp.
References error, and llvm_regerror().
Referenced by llvm::SpecialCaseList::Matcher::insert(), operator=(), and llvm::SpecialCaseList::parse().
bool Regex::match | ( | StringRef | String, |
SmallVectorImpl< StringRef > * | Matches = nullptr |
||
) |
matches - Match the regex against a given String
.
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. |
This returns true on a successful match.
Definition at line 73 of file Regex.cpp.
References assert(), llvm::SmallVectorImpl< T >::clear(), llvm::StringRef::data(), llvm::SmallVectorTemplateCommon< T >::data(), error, llvm_regexec(), adjust::pm(), llvm::SmallVectorTemplateBase< T, bool >::push_back(), rc, llvm_regex::re_nsub, REG_NOMATCH, REG_STARTEND, llvm::SmallVectorImpl< T >::resize(), and llvm::StringRef::size().
Referenced by FindFirstMatchingPrefix(), isModulePassName(), operator=(), llvm::AArch64SysReg::parseGenericRegister(), sub(), UpgradeIntrinsicFunction1(), and ValidateCheckPrefix().
Definition at line 50 of file Regex.h.
References error, escape(), getNumMatches(), isLiteralERE(), isValid(), match(), Regex(), llvm::String, sub(), std::swap(), and ~Regex().
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).
Error | If non-null, any errors in the substitution (invalid backreferences, trailing backslashes) will be recorded as a non-empty string. |
Definition at line 115 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(), Split(), llvm::StringRef::split(), and llvm::StringRef::substr().
Referenced by operator=(), and rewriteComdat().