From d6c1360c2bf234c73572a865f119d0518aca8154 Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Wed, 19 Mar 2008 05:07:26 +0000 Subject: [PATCH] More cleanups to the HTML rewriter (with line formatting), with better pretty-printing of line numbers. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@48533 91177308-0d34-0410-b5e6-96231b3b80d8 --- Driver/HTMLPrint.cpp | 21 ++++++++++++++------- lib/Rewrite/HTMLRewrite.cpp | 34 ++++++++++++++++++++++++++-------- 2 files changed, 40 insertions(+), 15 deletions(-) diff --git a/Driver/HTMLPrint.cpp b/Driver/HTMLPrint.cpp index acb011c216..93e544fc96 100644 --- a/Driver/HTMLPrint.cpp +++ b/Driver/HTMLPrint.cpp @@ -57,14 +57,21 @@ HTMLPrinter::~HTMLPrinter() { std::ostringstream os; os << "\n\n" - << " \n" << "\n" - << "\n
";
+       << "";
 
-    R.InsertTextBefore(StartLoc, os.str().c_str(), os.str().size());
+    R.InsertStrBefore(StartLoc, os.str());
   }
   
   // Generate footer
@@ -72,8 +79,8 @@ HTMLPrinter::~HTMLPrinter() {
   {
     std::ostringstream os;
     
-    os << "
\n\n"; - R.InsertTextAfter(EndLoc, os.str().c_str(), os.str().size()); + os << "\n"; + R.InsertStrAfter(EndLoc, os.str()); } diff --git a/lib/Rewrite/HTMLRewrite.cpp b/lib/Rewrite/HTMLRewrite.cpp index ddf427f1ad..9bd18109bb 100644 --- a/lib/Rewrite/HTMLRewrite.cpp +++ b/lib/Rewrite/HTMLRewrite.cpp @@ -49,16 +49,26 @@ void html::EscapeText(Rewriter& R, unsigned FileID, bool EscapeSpaces) { static void AddLineNumber(Rewriter& R, unsigned LineNo, SourceLocation B, SourceLocation E) { - // Surround the line with a span tag. + // Surround the line text with a div tag. - R.InsertTextBefore(E, "", 7); - R.InsertTextBefore(B, "", 18); + if (B == E) // Handle empty lines. + R.InsertCStrBefore(B, "
"); + else { + R.InsertCStrBefore(E, ""); + R.InsertCStrBefore(B, "
"); + } + + // Insert a div tag for the line number. - // Insert a span tag for the line number. - std::ostringstream os; - os << "" << LineNo << ""; - R.InsertTextBefore(B, os.str().c_str(), os.str().size()); + os << "
" << LineNo << "
"; + + R.InsertStrBefore(B, os.str()); + + // Now surround the whole line with another div tag. + + R.InsertCStrBefore(B, "
"); + R.InsertCStrAfter(E, "
"); } void html::AddLineNumbers(Rewriter& R, unsigned FileID) { @@ -98,5 +108,13 @@ void html::AddLineNumbers(Rewriter& R, unsigned FileID) { ++C; ++FilePos; } - } + } + + // Add one big div tag that surrounds all of the code. + + R.InsertCStrBefore(SourceLocation::getFileLoc(FileID, 0), + "
"); + + R.InsertCStrAfter(SourceLocation::getFileLoc(FileID, FileEnd - FileBeg), + "
"); } -- 2.40.0