From: Hans Wennborg Date: Thu, 12 Dec 2013 00:27:31 +0000 (+0000) Subject: Use llvm::Regex::Escape in VerifyDiagnosticConsumer.cpp X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=277c2adbe3de55bc9c32a72ca6beb56f2b5b06b9;p=clang Use llvm::Regex::Escape in VerifyDiagnosticConsumer.cpp This depends on LLVM r197096. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@197101 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Frontend/VerifyDiagnosticConsumer.cpp b/lib/Frontend/VerifyDiagnosticConsumer.cpp index b53fde257d..40992fec3f 100644 --- a/lib/Frontend/VerifyDiagnosticConsumer.cpp +++ b/lib/Frontend/VerifyDiagnosticConsumer.cpp @@ -851,36 +851,6 @@ void VerifyDiagnosticConsumer::CheckDiagnostics() { ED.Notes.clear(); } -// Add the characters from FixedStr to RegexStr, escaping as needed. This -// avoids the need for backslash-escaping in common patterns. -static void AddFixedStringToRegEx(StringRef FixedStr, std::string &RegexStr) { - // FIXME: Expose FileCheck.cpp's Pattern::AddFixedStringToRegEx as a utility - // method in RegEx. - - for (unsigned i = 0, e = FixedStr.size(); i != e; ++i) { - switch (FixedStr[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 += FixedStr[i]; - break; - } - } -} - Directive *Directive::create(bool RegexKind, SourceLocation DirectiveLoc, SourceLocation DiagnosticLoc, StringRef Text, unsigned Min, unsigned Max) { @@ -905,7 +875,7 @@ Directive *Directive::create(bool RegexKind, SourceLocation DirectiveLoc, if (VerbatimMatchLength == StringRef::npos) VerbatimMatchLength = S.size(); // Escape and append the fixed string. - AddFixedStringToRegEx(S.substr(0, VerbatimMatchLength), RegexStr); + RegexStr += llvm::Regex::escape(S.substr(0, VerbatimMatchLength)); S = S.drop_front(VerbatimMatchLength); } }