mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2026-04-20 16:17:38 +00:00
Expose FileCheck's AddFixedStringToRegEx as Regex::escape
Both FileCheck and clang's -verify need to escape strings for regexes, so let's expose this as a utility in the Regex class. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@197096 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -175,3 +175,32 @@ bool Regex::isLiteralERE(StringRef Str) {
|
||||
// regular expression specification.
|
||||
return Str.find_first_of("()^$|*+?.[]\\{}") == StringRef::npos;
|
||||
}
|
||||
|
||||
std::string Regex::escape(StringRef String) {
|
||||
std::string RegexStr;
|
||||
|
||||
for (unsigned i = 0, e = String.size(); i != e; ++i) {
|
||||
switch (String[i]) {
|
||||
// These are the special characters matched in "p_ere_exp".
|
||||
case '(':
|
||||
case ')':
|
||||
case '^':
|
||||
case '$':
|
||||
case '|':
|
||||
case '*':
|
||||
case '+':
|
||||
case '?':
|
||||
case '.':
|
||||
case '[':
|
||||
case '\\':
|
||||
case '{':
|
||||
RegexStr += '\\';
|
||||
// FALL THROUGH.
|
||||
default:
|
||||
RegexStr += String[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return RegexStr;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user