LLVM 22.0.0git
|
#include "llvm/Support/Regex.h"
Public Types | |
enum | RegexFlags : unsigned { NoFlags = 0 , IgnoreCase = 1 , Newline = 2 , BasicRegex = 4 } |
Public Member Functions | |
LLVM_ABI | Regex () |
LLVM_ABI | Regex (StringRef Regex, RegexFlags Flags=NoFlags) |
Compiles the given regular expression Regex . | |
LLVM_ABI | Regex (StringRef Regex, unsigned Flags) |
Regex (const Regex &)=delete | |
Regex & | operator= (Regex regex) |
LLVM_ABI | Regex (Regex &®ex) |
LLVM_ABI | ~Regex () |
LLVM_ABI bool | isValid (std::string &Error) const |
isValid - returns the error encountered during regex compilation, if any. | |
bool | isValid () const |
LLVM_ABI unsigned | getNumMatches () const |
getNumMatches - In a valid regex, return the number of parenthesized matches it contains. | |
LLVM_ABI bool | match (StringRef String, SmallVectorImpl< StringRef > *Matches=nullptr, std::string *Error=nullptr) const |
matches - Match the regex against a given String . | |
LLVM_ABI 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. |
Static Public Member Functions | |
static LLVM_ABI bool | isLiteralERE (StringRef Str) |
If this function returns true, ^Str$ is an extended regular expression that matches Str and only Str. | |
static LLVM_ABI std::string | escape (StringRef String) |
Turn String into a regex by escaping its special characters. |
enum llvm::Regex::RegexFlags : unsigned |
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 24 of file Regex.cpp.
References REG_BADPAT.
Referenced by operator=(), Regex(), Regex(), and Regex().
Regex::Regex | ( | StringRef | Regex, |
RegexFlags | Flags = NoFlags ) |
Compiles the given regular expression Regex
.
Regex | - referenced string is no longer needed after this constructor does finish. Only its compiled form is kept stored. |
Definition at line 26 of file Regex.cpp.
References BasicRegex, llvm::StringRef::data(), llvm::StringRef::end(), IgnoreCase, llvm_regcomp(), Newline, REG_EXTENDED, REG_ICASE, REG_NEWLINE, and REG_PEND.
Regex::Regex | ( | Regex && | regex | ) |
Definition at line 42 of file Regex.cpp.
References REG_BADPAT, and Regex().
Regex::~Regex | ( | ) |
Definition at line 49 of file Regex.cpp.
References llvm_regfree().
|
static |
Turn String into a regex by escaping its special characters.
Definition at line 239 of file Regex.cpp.
References llvm::CallingConv::C, RegexMetachars, and llvm::String.
Referenced by llvm::StringSubstitution::getResultRegex(), and llvm::Pattern::parsePattern().
unsigned Regex::getNumMatches | ( | ) | const |
If this function returns true, ^Str$ is an extended regular expression that matches Str and only Str.
Definition at line 232 of file Regex.cpp.
References llvm::StringRef::npos, and RegexMetachars.
|
inline |
bool Regex::isValid | ( | std::string & | Error | ) | const |
isValid - returns the error encountered during regex compilation, if any.
Definition at line 69 of file Regex.cpp.
Referenced by llvm::objcopy::NameOrPattern::create(), llvm::MachO::createRegexFromGlob(), llvm::BinOpInit::Fold(), llvm::InstancesOpInit::Fold(), and llvm::SpecialCaseList::Matcher::insert().
bool Regex::match | ( | StringRef | String, |
SmallVectorImpl< StringRef > * | Matches = nullptr, | ||
std::string * | Error = nullptr ) const |
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. |
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 83 of file Regex.cpp.
References assert(), llvm::SmallVectorImpl< T >::clear(), llvm::SmallVectorTemplateCommon< T, typename >::data(), isValid(), llvm_regexec(), llvm::SmallVectorTemplateBase< T, bool >::push_back(), rc, REG_NOMATCH, REG_STARTEND, llvm::SmallVectorImpl< T >::resize(), and llvm::String.
Referenced by llvm::BinOpInit::Fold(), llvm::InstancesOpInit::Fold(), llvm::M68kInstrInfo::isPCRelRegisterOperandLegal(), llvm::SpecialCaseList::Matcher::match(), llvm::AArch64SysReg::parseGenericRegister(), sub(), upgradeArmOrAarch64IntrinsicFunction(), and ValidatePrefixes().
Definition at line 57 of file Regex.h.
References Regex(), and std::swap().
sub - Return the result of replacing the first match of the regex in String
with the Repl
string.
Backreferences like "\0" and "\g<1>" 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. If there is no error, it will be an empty string. |
Definition at line 137 of file Regex.cpp.
References llvm::SmallVectorTemplateCommon< T, typename >::begin(), llvm::StringRef::empty(), llvm::SmallVectorTemplateCommon< T, typename >::end(), llvm::StringRef::find(), llvm::StringRef::find_first_not_of(), match(), llvm::StringRef::npos, llvm::Ref, llvm::SmallVectorTemplateCommon< T, typename >::size(), llvm::StringRef::size(), llvm::StringRef::slice(), llvm::StringRef::split(), llvm::String, and llvm::StringRef::substr().