aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVedant Kumar <vsk@apple.com>2018-05-30 23:35:14 +0000
committerVedant Kumar <vsk@apple.com>2018-05-30 23:35:14 +0000
commite3c1fb8b124246343f20b98f4035b61dd3ccd7df (patch)
tree00e0139e0c109611a5e5f67de5fa2dc34a687572
parent1c6961d3bae1ddd19f97cbd58be688ed50cee190 (diff)
downloadllvm-e3c1fb8b124246343f20b98f4035b61dd3ccd7df.zip
llvm-e3c1fb8b124246343f20b98f4035b61dd3ccd7df.tar.gz
llvm-e3c1fb8b124246343f20b98f4035b61dd3ccd7df.tar.bz2
[llvm-cov] Use the new PrintHTMLEscaped utility
This removes some duplicate logic to escape characters in HTML output. llvm-svn: 333608
-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 6f10c3b..c9fea2b 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: &nbsp;&nbsp;(void) &quot;This tab starts at column 0&quot;;
- (void) " This tab starts at column 10"; // CHECK: (void) &quot;&nbsp;&nbsp;This tab starts at column 10&quot;;
- (void) "This tab starts at column 15"; // CHECK: (void) &quot;This &nbsp; tab starts at column 15&quot;;
+ (void) "This tab starts at column 0"; // CHECK: > (void) &quot;This tab starts at column 0&quot;;
+ (void) " This tab starts at column 10"; // CHECK: > (void) &quot; This tab starts at column 10&quot;;
+ (void) "This tab starts at column 15"; // CHECK: > (void) &quot;This tab starts at column 15&quot;;
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: &nbsp;&nbsp;&nbsp;(void) &quot;This tab starts at column 0&quot;;
-// CHECK-TABSIZE: (void) &quot;&nbsp;&nbsp;This tab starts at column 10&quot;;
-// CHECK-TABSIZE: (void) &quot;This &nbsp;&nbsp;&nbsp; tab starts at column 15&quot;;
+// CHECK-TABSIZE: > (void) &quot;This tab starts at column 0&quot;;
+// CHECK-TABSIZE: > (void) &quot; This tab starts at column 10&quot;;
+// CHECK-TABSIZE: > (void) &quot;This tab starts at column 15&quot;;
diff --git a/llvm/tools/llvm-cov/SourceCoverageViewHTML.cpp b/llvm/tools/llvm-cov/SourceCoverageViewHTML.cpp
index e8105ab..330da8bd 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 += "&amp;";
- 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.