63 Error.resize(len - 1);
73 RegexErrorToString(error, preg,
Error);
84 std::string *
Error)
const {
93 unsigned nmatch = Matches ? preg->
re_nsub+1 : 0;
96 if (
String.data() ==
nullptr)
101 pm.
resize(nmatch > 0 ? nmatch : 1);
103 pm[0].rm_eo =
String.size();
113 RegexErrorToString(error, preg, *
Error);
122 for (
unsigned i = 0; i != nmatch; ++i) {
123 if (pm[i].rm_so == -1) {
128 assert(pm[i].rm_eo >= pm[i].rm_so);
130 pm[i].rm_eo-pm[i].rm_so));
138 std::string *
Error)
const {
143 return std::string(
String);
147 std::string Res(
String.begin(), Matches[0].
begin());
150 while (!Repl.
empty()) {
152 std::pair<StringRef, StringRef> Split = Repl.
split(
'\\');
158 if (Split.second.empty()) {
159 if (Repl.
size() != Split.first.size() &&
161 *
Error =
"replacement string contained trailing backslash";
173 if (Repl.
size() >= 4 && Repl[1] ==
'<') {
179 if (RefValue < Matches.
size())
180 Res += Matches[RefValue];
183 (
"invalid backreference string 'g<" +
Twine(
Ref) +
">'").str();
206 case '0':
case '1':
case '2':
case '3':
case '4':
207 case '5':
case '6':
case '7':
case '8':
case '9': {
213 if (!
Ref.getAsInteger(10, RefValue) &&
214 RefValue < Matches.
size())
215 Res += Matches[RefValue];
217 *
Error = (
"invalid backreference string '" +
Twine(
Ref) +
"'").str();
240 std::string RegexStr;
static const char RegexMetachars[]
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file defines the SmallVector class.
Lightweight error class with error context and mandatory checking.
@ Newline
Compile for newline-sensitive matching.
@ IgnoreCase
Compile for matching that ignores upper/lower case distinctions.
@ BasicRegex
By default, the POSIX extended regular expression (ERE) syntax is assumed.
static std::string escape(StringRef String)
Turn String into a regex by escaping its special characters.
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 bool isLiteralERE(StringRef Str)
If this function returns true, ^Str$ is an extended regular expression that matches Str and only Str.
unsigned getNumMatches() const
getNumMatches - In a valid regex, return the number of parenthesized matches it contains.
bool match(StringRef String, SmallVectorImpl< StringRef > *Matches=nullptr, std::string *Error=nullptr) const
matches - Match the regex against a given String.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void push_back(const T &Elt)
pointer data()
Return a pointer to the vector's buffer, even if empty().
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
constexpr StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
constexpr bool empty() const
empty - Check if the string is empty.
StringRef slice(size_t Start, size_t End) const
Return a reference to the substring from [Start, End).
constexpr size_t size() const
size - Get the string size.
constexpr const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
size_t find(char C, size_t From=0) const
Search for the first character C in the string.
static constexpr size_t npos
size_t find_first_not_of(char C, size_t From=0) const
Find the first character in the string that is not C or npos if not found.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
@ C
The default llvm calling convention, compatible with C.
This is an optimization pass for GlobalISel generic memory operations.
@ Ref
The access may reference the value stored in memory.
int llvm_regcomp(llvm_regex_t *preg, const char *pattern, int cflags)
size_t llvm_regerror(int errcode, const llvm_regex_t *preg, char *errbuf, size_t errbuf_size)
void llvm_regfree(llvm_regex_t *)
int llvm_regexec(const llvm_regex_t *, const char *, size_t, llvm_regmatch_t[], int)