From 5c176f7a9ba9f7084b903393845be24f85e091da Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Fri, 18 Apr 2008 04:54:20 +0000 Subject: [PATCH] Make tab insertion really right: the number of spaces inserted 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 | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/lib/Rewrite/HTMLRewrite.cpp b/lib/Rewrite/HTMLRewrite.cpp index 8074c8dc33..d0d1ff0b93 100644 --- a/lib/Rewrite/HTMLRewrite.cpp +++ b/lib/Rewrite/HTMLRewrite.cpp @@ -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, " ", 6); + ++ColNo; break; - case '\t': + case '\t': { if (!ReplaceTabs) break; + unsigned NumSpaces = 8-(ColNo&7); if (EscapeSpaces) RB.ReplaceText(FilePos, 1, "     " - "   ", 6*8); + "   ", 6*NumSpaces); else - RB.ReplaceText(FilePos, 1, " ", 8); + RB.ReplaceText(FilePos, 1, " ", NumSpaces); + ColNo += NumSpaces; break; - + } case '<': RB.ReplaceText(FilePos, 1, "<", 4); + ++ColNo; break; case '>': RB.ReplaceText(FilePos, 1, ">", 4); + ++ColNo; break; case '&': RB.ReplaceText(FilePos, 1, "&", 5); + ++ColNo; break; } } -- 2.40.0