62 Error.resize(len - 1);
72 RegexErrorToString(
error, preg, Error);
83 std::string *
Error)
const {
85 if (Error && !Error->empty())
92 unsigned nmatch = Matches ? preg->re_nsub+1 : 0;
96 pm.
resize(nmatch > 0 ? nmatch : 1);
98 pm[0].rm_eo = String.
size();
108 RegexErrorToString(
error, preg, *Error);
117 for (
unsigned i = 0; i != nmatch; ++i) {
118 if (pm[i].rm_so == -1) {
123 assert(pm[i].rm_eo >= pm[i].rm_so);
125 pm[i].rm_eo-pm[i].rm_so));
133 std::string *
Error)
const {
137 if (!
match(String, &Matches, Error))
142 std::string Res(String.
begin(), Matches[0].
begin());
145 while (!Repl.
empty()) {
147 std::pair<StringRef, StringRef> Split = Repl.
split(
'\\');
153 if (Split.second.empty()) {
154 if (Repl.
size() != Split.first.size() &&
155 Error && Error->empty())
156 *Error =
"replacement string contained trailing backslash";
182 case '0':
case '1':
case '2':
case '3':
case '4':
183 case '5':
case '6':
case '7':
case '8':
case '9': {
190 RefValue < Matches.
size())
191 Res += Matches[RefValue];
192 else if (Error && Error->empty())
193 *Error = (
"invalid backreference string '" +
Twine(Ref) +
"'").str();
216 std::string RegexStr;
217 for (
unsigned i = 0,
e = String.
size(); i !=
e; ++i) {
218 if (strchr(RegexMetachars, String[i]))
220 RegexStr += String[i];
const_iterator end(StringRef path)
Get end iterator over path.
This class represents lattice values for constants.
void push_back(const T &Elt)
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.
int llvm_regcomp(llvm_regex_t *preg, const char *pattern, int cflags)
void llvm_regfree(llvm_regex_t *)
Compile for matching that ignores upper/lower case distinctions.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
The access may reference the value stored in memory.
LLVM_NODISCARD StringRef slice(size_t Start, size_t End) const
Return a reference to the substring from [Start, End).
LLVM_NODISCARD StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
bool match(StringRef String, SmallVectorImpl< StringRef > *Matches=nullptr, std::string *Error=nullptr) const
matches - Match the regex against a given String.
size_t llvm_regerror(int errcode, const llvm_regex_t *preg, char *errbuf, size_t errbuf_size)
LLVM_NODISCARD size_t size() const
size - Get the string size.
LLVM_NODISCARD 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.
static const char RegexMetachars[]
static bool isLiteralERE(StringRef Str)
If this function returns true, ^Str$ is an extended regular expression that matches Str and only Str...
void pm(uint64_t &Value)
Adjusts a program memory address.
std::enable_if< std::numeric_limits< T >::is_signed, bool >::type getAsInteger(unsigned Radix, T &Result) const
Parse the current string as an integer of the specified radix.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
LLVM_NODISCARD std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
unsigned getNumMatches() const
getNumMatches - In a valid regex, return the number of parenthesized matches it contains.
pointer data()
Return a pointer to the vector's buffer, even if empty().
LLVM_NODISCARD size_t find_first_of(char C, size_t From=0) const
Find the first character in the string that is C, or npos if not found.
int llvm_regexec(const llvm_regex_t *, const char *, size_t, llvm_regmatch_t [], int)
LLVM_NODISCARD const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
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...
Lightweight error class with error context and mandatory checking.
Compile for newline-sensitive matching.
StringRef - Represent a constant reference to a string, i.e.