summaryrefslogtreecommitdiff
path: root/lib/Support/Regex.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Support/Regex.cpp')
-rw-r--r--lib/Support/Regex.cpp29
1 files changed, 29 insertions, 0 deletions
diff --git a/lib/Support/Regex.cpp b/lib/Support/Regex.cpp
index 5413641840..3e112df6c7 100644
--- a/lib/Support/Regex.cpp
+++ b/lib/Support/Regex.cpp
@@ -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;
+}