summaryrefslogtreecommitdiffstats
path: root/contrib/llvm/lib/Support/Regex.cpp
diff options
context:
space:
mode:
authordim <dim@FreeBSD.org>2014-11-24 17:02:24 +0000
committerdim <dim@FreeBSD.org>2014-11-24 17:02:24 +0000
commit2c8643c6396b0a3db33430cf9380e70bbb9efce0 (patch)
tree4df130b28021d86e13bf4565ef58c1c5a5e093b4 /contrib/llvm/lib/Support/Regex.cpp
parent678318cd20f7db4e6c6b85d83fe00fa327b04fca (diff)
parente27feadae0885aa074df58ebfda2e7a7f7a7d590 (diff)
downloadFreeBSD-src-2c8643c6396b0a3db33430cf9380e70bbb9efce0.zip
FreeBSD-src-2c8643c6396b0a3db33430cf9380e70bbb9efce0.tar.gz
Merge llvm 3.5.0 release from ^/vendor/llvm/dist, resolve conflicts, and
preserve our customizations, where necessary.
Diffstat (limited to 'contrib/llvm/lib/Support/Regex.cpp')
-rw-r--r--contrib/llvm/lib/Support/Regex.cpp24
1 files changed, 20 insertions, 4 deletions
diff --git a/contrib/llvm/lib/Support/Regex.cpp b/contrib/llvm/lib/Support/Regex.cpp
index 5413641..f7fe1e4 100644
--- a/contrib/llvm/lib/Support/Regex.cpp
+++ b/contrib/llvm/lib/Support/Regex.cpp
@@ -33,15 +33,17 @@ Regex::Regex(StringRef regex, unsigned Flags) {
}
Regex::~Regex() {
- llvm_regfree(preg);
- delete preg;
+ if (preg) {
+ llvm_regfree(preg);
+ delete preg;
+ }
}
bool Regex::isValid(std::string &Error) {
if (!error)
return true;
- size_t len = llvm_regerror(error, preg, NULL, 0);
+ size_t len = llvm_regerror(error, preg, nullptr, 0);
Error.resize(len - 1);
llvm_regerror(error, preg, &Error[0], len);
@@ -169,9 +171,23 @@ std::string Regex::sub(StringRef Repl, StringRef String,
return Res;
}
+// These are the special characters matched in functions like "p_ere_exp".
+static const char RegexMetachars[] = "()^$|*+?.[]\\{}";
+
bool Regex::isLiteralERE(StringRef Str) {
// Check for regex metacharacters. This list was derived from our regex
// implementation in regcomp.c and double checked against the POSIX extended
// regular expression specification.
- return Str.find_first_of("()^$|*+?.[]\\{}") == StringRef::npos;
+ return Str.find_first_of(RegexMetachars) == StringRef::npos;
+}
+
+std::string Regex::escape(StringRef String) {
+ std::string RegexStr;
+ for (unsigned i = 0, e = String.size(); i != e; ++i) {
+ if (strchr(RegexMetachars, String[i]))
+ RegexStr += '\\';
+ RegexStr += String[i];
+ }
+
+ return RegexStr;
}
OpenPOWER on IntegriCloud