r197101 - Use llvm::Regex::Escape in VerifyDiagnosticConsumer.cpp

Hans Wennborg hans at hanshq.net
Wed Dec 11 16:27:31 PST 2013


Author: hans
Date: Wed Dec 11 18:27:31 2013
New Revision: 197101

URL: http://llvm.org/viewvc/llvm-project?rev=197101&view=rev
Log:
Use llvm::Regex::Escape in VerifyDiagnosticConsumer.cpp

This depends on LLVM r197096.

Modified:
    cfe/trunk/lib/Frontend/VerifyDiagnosticConsumer.cpp

Modified: cfe/trunk/lib/Frontend/VerifyDiagnosticConsumer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/VerifyDiagnosticConsumer.cpp?rev=197101&r1=197100&r2=197101&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/VerifyDiagnosticConsumer.cpp (original)
+++ cfe/trunk/lib/Frontend/VerifyDiagnosticConsumer.cpp Wed Dec 11 18:27:31 2013
@@ -851,36 +851,6 @@ void VerifyDiagnosticConsumer::CheckDiag
   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 RegexK
       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);
     }
   }





More information about the cfe-commits mailing list