48 Error.resize(len - 1);
60 unsigned nmatch = Matches ? preg->
re_nsub+1 : 0;
64 pm.
resize(nmatch > 0 ? nmatch : 1);
66 pm[0].rm_eo = String.
size();
83 for (
unsigned i = 0; i != nmatch; ++i) {
84 if (pm[i].rm_so == -1) {
89 assert(pm[i].rm_eo >= pm[i].rm_so);
91 pm[i].rm_eo-pm[i].rm_so));
103 if (Error && !Error->empty()) *Error =
"";
106 if (!
match(String, &Matches))
111 std::string Res(String.
begin(), Matches[0].
begin());
114 while (!Repl.
empty()) {
116 std::pair<StringRef, StringRef>
Split = Repl.
split(
'\\');
122 if (Split.second.empty()) {
123 if (Repl.
size() != Split.first.size() &&
124 Error && Error->empty())
125 *Error =
"replacement string contained trailing backslash";
151 case '0':
case '1':
case '2':
case '3':
case '4':
152 case '5':
case '6':
case '7':
case '8':
case '9': {
159 RefValue < Matches.
size())
160 Res += Matches[RefValue];
161 else if (Error && Error->empty())
162 *Error = (
"invalid backreference string '" +
Twine(Ref) +
"'").str();
185 std::string RegexStr;
186 for (
unsigned i = 0, e = String.
size(); i != e; ++i) {
189 RegexStr += String[i];
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.
void push_back(const T &Elt)
const_iterator end(StringRef path)
Get end iterator over path.
size_t size() const
size - Get the string size.
std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
static std::string escape(StringRef String)
Turn String into a regex by escaping its special characters.
StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
int llvm_regcomp(llvm_regex_t *preg, const char *pattern, int cflags)
void llvm_regfree(llvm_regex_t *)
By default, the POSIX extended regular expression (ERE) syntax is assumed.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
bool isValid(std::string &Error)
isValid - returns the error encountered during regex compilation, or matching, if any...
const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
size_t llvm_regerror(int errcode, const llvm_regex_t *preg, char *errbuf, size_t errbuf_size)
static std::error_code error(DiagnosticHandlerFunction DiagnosticHandler, std::error_code EC, const Twine &Message)
Compile for newline-sensitive matching.
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...
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...
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.
unsigned getNumMatches() const
getNumMatches - In a valid regex, return the number of parenthesized matches it contains.
Regex(StringRef Regex, unsigned Flags=NoFlags)
Compiles the given regular expression Regex.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
int llvm_regexec(const llvm_regex_t *, const char *, size_t, llvm_regmatch_t[], int)
pointer data()
Return a pointer to the vector's buffer, even if empty().
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.
Compile for matching that ignores upper/lower case distinctions.
bool match(StringRef String, SmallVectorImpl< StringRef > *Matches=nullptr)
matches - Match the regex against a given String.
StringRef - Represent a constant reference to a string, i.e.
StringRef slice(size_t Start, size_t End) const
Return a reference to the substring from [Start, End).
static void Split(std::vector< std::string > &V, StringRef S)
Split - Splits a string of comma separated items in to a vector of strings.
bool empty() const
empty - Check if the string is empty.