[cfe-commits] r48884 - in /cfe/trunk: Driver/HTMLDiagnostics.cpp include/clang/Rewrite/HTMLRewrite.h lib/Rewrite/HTMLRewrite.cpp

Ted Kremenek kremenek at apple.com
Thu Mar 27 10:15:30 PDT 2008


Author: kremenek
Date: Thu Mar 27 12:15:29 2008
New Revision: 48884

URL: http://llvm.org/viewvc/llvm-project?rev=48884&view=rev
Log:
Add html::EscapeText for std::string; use this function to escape text in message bubbles.

Modified:
    cfe/trunk/Driver/HTMLDiagnostics.cpp
    cfe/trunk/include/clang/Rewrite/HTMLRewrite.h
    cfe/trunk/lib/Rewrite/HTMLRewrite.cpp

Modified: cfe/trunk/Driver/HTMLDiagnostics.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/HTMLDiagnostics.cpp?rev=48884&r1=48883&r2=48884&view=diff

==============================================================================
--- cfe/trunk/Driver/HTMLDiagnostics.cpp (original)
+++ cfe/trunk/Driver/HTMLDiagnostics.cpp Thu Mar 27 12:15:29 2008
@@ -117,8 +117,8 @@
     std::ostringstream os;
     const FileEntry* Entry = SMgr.getFileEntryForID(FileID);
     
-    os << "<h1>" << Entry->getDir()->getName() << "/"
-       << Entry->getName() << "</h1>\n";
+    os << "<h1>" << html::EscapeText(Entry->getDir()->getName())
+       << "/" << html::EscapeText(Entry->getName()) << "</h1>\n";
 
     R.InsertStrBefore(SourceLocation::getFileLoc(FileID, 0), os.str());
   }  
@@ -200,7 +200,7 @@
      << "<div class=\"msg\" style=\"margin-left:"
      << ColNo << "ex\">";
   
-  os << P.getString() << "</div></td></tr>";
+  os << html::EscapeText(P.getString()) << "</div></td></tr>";
   
   // Insert the new html.
   

Modified: cfe/trunk/include/clang/Rewrite/HTMLRewrite.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Rewrite/HTMLRewrite.h?rev=48884&r1=48883&r2=48884&view=diff

==============================================================================
--- cfe/trunk/include/clang/Rewrite/HTMLRewrite.h (original)
+++ cfe/trunk/include/clang/Rewrite/HTMLRewrite.h Thu Mar 27 12:15:29 2008
@@ -16,6 +16,7 @@
 #define LLVM_CLANG_HTMLREWRITER_H
 
 #include "clang/Basic/SourceLocation.h"
+#include <string>
 
 namespace clang {
   
@@ -24,7 +25,8 @@
 namespace html {
 
   void EscapeText(Rewriter& R, unsigned FileID, bool EscapeSpaces = false);
-  
+  std::string EscapeText(const std::string& s, bool EscapeSpaces = false);
+
   void AddLineNumbers(Rewriter& R, unsigned FileID);  
   
   void AddHeaderFooterInternalBuiltinCSS(Rewriter& R, unsigned FileID);

Modified: cfe/trunk/lib/Rewrite/HTMLRewrite.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Rewrite/HTMLRewrite.cpp?rev=48884&r1=48883&r2=48884&view=diff

==============================================================================
--- cfe/trunk/lib/Rewrite/HTMLRewrite.cpp (original)
+++ cfe/trunk/lib/Rewrite/HTMLRewrite.cpp Thu Mar 27 12:15:29 2008
@@ -46,6 +46,32 @@
   }
 }
 
+std::string html::EscapeText(const std::string& s, bool EscapeSpaces) {
+  
+  unsigned len = s.size();
+  std::ostringstream os;
+  
+  for (unsigned i = 0 ; i < len; ++i) {
+    
+    char c = s[i];
+    
+    switch (c) {
+      default:
+        os << c; break;
+        
+      case ' ':
+        if (EscapeSpaces) os << " ";
+        break;
+        
+        case '<': os << "<"; break;
+        case '>': os << ">"; break;
+        case '&': os << "&"; break;
+    }
+  }
+  
+  return os.str();
+}
+
 static void AddLineNumber(Rewriter& R, unsigned LineNo,
                           SourceLocation B, SourceLocation E) {
     





More information about the cfe-commits mailing list