summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--llvm/test/tools/llvm-cov/showTabsHTML.cpp14
-rw-r--r--llvm/tools/llvm-cov/SourceCoverageViewHTML.cpp38
2 files changed, 25 insertions, 27 deletions
diff --git a/llvm/test/tools/llvm-cov/showTabsHTML.cpp b/llvm/test/tools/llvm-cov/showTabsHTML.cpp
index 6f10c3b539f..c9fea2b1680 100644
--- a/llvm/test/tools/llvm-cov/showTabsHTML.cpp
+++ b/llvm/test/tools/llvm-cov/showTabsHTML.cpp
@@ -1,16 +1,16 @@
// RUN: llvm-profdata merge -o %t.profdata %S/Inputs/showTabsHTML.proftext
-// RUN: llvm-cov show %S/Inputs/showTabsHTML.covmapping -format html -instr-profile %t.profdata -path-equivalence=/tmp,%S %s | FileCheck %s
+// RUN: llvm-cov show %S/Inputs/showTabsHTML.covmapping -format html -instr-profile %t.profdata -path-equivalence=/tmp,%S %s | FileCheck %s --strict-whitespace
int main(int argc, char ** argv) {
- (void) "This tab starts at column 0"; // CHECK:   (void) "This tab starts at column 0";
- (void) " This tab starts at column 10"; // CHECK: (void) "  This tab starts at column 10";
- (void) "This tab starts at column 15"; // CHECK: (void) "This   tab starts at column 15";
+ (void) "This tab starts at column 0"; // CHECK: > (void) "This tab starts at column 0";
+ (void) " This tab starts at column 10"; // CHECK: > (void) " This tab starts at column 10";
+ (void) "This tab starts at column 15"; // CHECK: > (void) "This tab starts at column 15";
return 0;
}
// RUN: llvm-cov show %S/Inputs/showTabsHTML.covmapping -format html -tab-size=3 -instr-profile %t.profdata -path-equivalence=/tmp,%S %s | FileCheck -check-prefix=CHECK-TABSIZE %s
-// CHECK-TABSIZE:    (void) "This tab starts at column 0";
-// CHECK-TABSIZE: (void) "  This tab starts at column 10";
-// CHECK-TABSIZE: (void) "This     tab starts at column 15";
+// CHECK-TABSIZE: > (void) "This tab starts at column 0";
+// CHECK-TABSIZE: > (void) " This tab starts at column 10";
+// CHECK-TABSIZE: > (void) "This tab starts at column 15";
diff --git a/llvm/tools/llvm-cov/SourceCoverageViewHTML.cpp b/llvm/tools/llvm-cov/SourceCoverageViewHTML.cpp
index e8105ab8da0..330da8bd8b7 100644
--- a/llvm/tools/llvm-cov/SourceCoverageViewHTML.cpp
+++ b/llvm/tools/llvm-cov/SourceCoverageViewHTML.cpp
@@ -25,31 +25,29 @@ namespace {
// Return a string with the special characters in \p Str escaped.
std::string escape(StringRef Str, const CoverageViewOptions &Opts) {
- std::string Result;
+ std::string TabExpandedResult;
unsigned ColNum = 0; // Record the column number.
for (char C : Str) {
- ++ColNum;
- if (C == '&')
- Result += "&";
- else if (C == '<')
- Result += "&lt;";
- else if (C == '>')
- Result += "&gt;";
- else if (C == '\"')
- Result += "&quot;";
- else if (C == '\n' || C == '\r') {
- Result += C;
- ColNum = 0;
- } else if (C == '\t') {
- // Replace '\t' with TabSize spaces.
- unsigned NumSpaces = Opts.TabSize - (--ColNum % Opts.TabSize);
+ if (C == '\t') {
+ // Replace '\t' with up to TabSize spaces.
+ unsigned NumSpaces = Opts.TabSize - (ColNum % Opts.TabSize);
for (unsigned I = 0; I < NumSpaces; ++I)
- Result += "&nbsp;";
+ TabExpandedResult += ' ';
ColNum += NumSpaces;
- } else
- Result += C;
+ } else {
+ TabExpandedResult += C;
+ if (C == '\n' || C == '\r')
+ ColNum = 0;
+ else
+ ++ColNum;
+ }
+ }
+ std::string EscapedHTML;
+ {
+ raw_string_ostream OS{EscapedHTML};
+ PrintHTMLEscaped(TabExpandedResult, OS);
}
- return Result;
+ return EscapedHTML;
}
// Create a \p Name tag around \p Str, and optionally set its \p ClassName.
OpenPOWER on IntegriCloud