]> granicus.if.org Git - clang/commitdiff
Don't expand tabs in EscapeText, but rather expand them when writing out
authorTed Kremenek <kremenek@apple.com>
Tue, 8 Apr 2008 22:37:58 +0000 (22:37 +0000)
committerTed Kremenek <kremenek@apple.com>
Tue, 8 Apr 2008 22:37:58 +0000 (22:37 +0000)
the HTML file.  This should reduce the amount of memory pressure on the
rewriter for files that have a lot of tabs.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@49406 91177308-0d34-0410-b5e6-96231b3b80d8

Driver/HTMLDiagnostics.cpp
include/clang/Rewrite/HTMLRewrite.h
lib/Rewrite/HTMLRewrite.cpp

index 870628963aa5384b996914d083b65a5135d25853..6910af74d06d1664bb1ab22ea50b013fad0dedc2 100644 (file)
@@ -199,8 +199,13 @@ void HTMLDiagnostics::HandlePathDiagnostic(const PathDiagnostic& D) {
   
   // Emit the HTML to disk.
 
-  for (RewriteBuffer::iterator I = Buf->begin(), E = Buf->end(); I!=E; ++I)
-    os << *I;  
+  for (RewriteBuffer::iterator I = Buf->begin(), E = Buf->end(); I!=E; ++I) {
+    // Expand tabs.
+    if (*I == '\t')
+      os << "   ";
+    else  
+      os << *I;
+  }
 }
 
 void HTMLDiagnostics::HandlePiece(Rewriter& R,
index b8f9b95913a561b91d8ed10b0ac4c6acb957094f..d5bdc8907043f7848affafeab3e84b30d55c9c56 100644 (file)
@@ -24,8 +24,20 @@ class Rewriter;
   
 namespace html {
 
-  void EscapeText(Rewriter& R, unsigned FileID, bool EscapeSpaces = false);
-  std::string EscapeText(const std::string& s, bool EscapeSpaces = false);
+  /// EscapeText - HTMLize a specified file so that special characters are
+  /// are translated so that they are not interpreted as HTML tags.  In this
+  /// version tabs are not replaced with spaces by default, as this can
+  /// introduce a serious performance overhead as the amount of replaced
+  /// text can be very large.
+  void EscapeText(Rewriter& R, unsigned FileID,
+                  bool EscapeSpaces = false, bool ReplacesTabs = false);
+
+  /// EscapeText - HTMLized the provided string so that special characters
+  ///  in 's' are not interpreted as HTML tags.  Unlike the version of
+  ///  EscapeText that rewrites a file, this version by default replaces tabs
+  ///  with spaces.
+  std::string EscapeText(const std::string& s,
+                         bool EscapeSpaces = false, bool ReplaceTabs = true);
 
   void AddLineNumbers(Rewriter& R, unsigned FileID);  
   
index 8bc44e3a819d8fca697796b8d9ac02e403020126..3e0d71a5b6d09cdcc52d3ad26c9559217cf4384c 100644 (file)
@@ -20,7 +20,8 @@
 
 using namespace clang;
 
-void html::EscapeText(Rewriter& R, unsigned FileID, bool EscapeSpaces) {
+void html::EscapeText(Rewriter& R, unsigned FileID,
+                      bool EscapeSpaces, bool ReplaceTabs) {
   
   const llvm::MemoryBuffer *Buf = R.getSourceMgr().getBuffer(FileID);
   const char* C = Buf->getBufferStart();
@@ -41,6 +42,9 @@ void html::EscapeText(Rewriter& R, unsigned FileID, bool EscapeSpaces) {
         break;
 
       case '\t': {
+        if (!ReplaceTabs)
+          break;
+        
         SourceLocation Loc = SourceLocation::getFileLoc(FileID, FilePos);
         
         if (EscapeSpaces)
@@ -72,7 +76,8 @@ void html::EscapeText(Rewriter& R, unsigned FileID, bool EscapeSpaces) {
   }
 }
 
-std::string html::EscapeText(const std::string& s, bool EscapeSpaces) {
+std::string html::EscapeText(const std::string& s, bool EscapeSpaces,
+                             bool ReplaceTabs) {
   
   unsigned len = s.size();
   std::ostringstream os;
@@ -90,7 +95,13 @@ std::string html::EscapeText(const std::string& s, bool EscapeSpaces) {
         else os << ' ';
         break;
         
-        case '\t': for (unsigned i = 0; i < 4; ++i) os << "&nbsp;"; break;
+        case '\t':
+          if (ReplaceTabs)
+            for (unsigned i = 0; i < 4; ++i) os << "&nbsp;";
+          else os << c;
+        
+          break;
+        
         case '<': os << "&lt;"; break;
         case '>': os << "&gt;"; break;
         case '&': os << "&amp;"; break;