]> granicus.if.org Git - clang/commitdiff
Make tab insertion really right: the number of spaces inserted
authorChris Lattner <sabre@nondot.org>
Fri, 18 Apr 2008 04:54:20 +0000 (04:54 +0000)
committerChris Lattner <sabre@nondot.org>
Fri, 18 Apr 2008 04:54:20 +0000 (04:54 +0000)
depends on the column number of the start of the tab.

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

lib/Rewrite/HTMLRewrite.cpp

index 8074c8dc33dfcf8799332ccaf17fc2e2cec6651b..d0d1ff0b935e106b0e084ce151fcbf5187432b2b 100644 (file)
@@ -107,37 +107,47 @@ void html::EscapeText(Rewriter& R, unsigned FileID,
   assert (C <= FileEnd);
   
   RewriteBuffer &RB = R.getEditBuffer(FileID);
-  
+
+  unsigned ColNo = 0;
   for (unsigned FilePos = 0; C != FileEnd ; ++C, ++FilePos) {
-      
     switch (*C) {
-    default: break;
+    default: ++ColNo; break;
+    case '\n':
+    case '\r':
+      ColNo = 0;
+      break;
       
     case ' ':
       if (EscapeSpaces)
         RB.ReplaceText(FilePos, 1, "&nbsp;", 6);
+      ++ColNo;
       break;
 
-    case '\t':
+    case '\t': {
       if (!ReplaceTabs)
         break;
+      unsigned NumSpaces = 8-(ColNo&7);
       if (EscapeSpaces)
         RB.ReplaceText(FilePos, 1, "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"
-                       "&nbsp;&nbsp;&nbsp;", 6*8);
+                       "&nbsp;&nbsp;&nbsp;", 6*NumSpaces);
       else
-        RB.ReplaceText(FilePos, 1, "        ", 8);
+        RB.ReplaceText(FilePos, 1, "        ", NumSpaces);
+      ColNo += NumSpaces;
       break;
-      
+    }
     case '<':
       RB.ReplaceText(FilePos, 1, "&lt;", 4);
+      ++ColNo;
       break;
       
     case '>':
       RB.ReplaceText(FilePos, 1, "&gt;", 4);
+      ++ColNo;
       break;
       
     case '&':
       RB.ReplaceText(FilePos, 1, "&amp;", 5);
+      ++ColNo;
       break;
     }
   }