[llvm] r333608 - [llvm-cov] Use the new PrintHTMLEscaped utility
Adrian Prantl via llvm-commits
llvm-commits at lists.llvm.org
Thu May 31 09:48:45 PDT 2018
I'm not sure if this matters but the handling of spaces is now different (' ' vs ' ').
-- adrian
> On May 30, 2018, at 4:35 PM, Vedant Kumar via llvm-commits <llvm-commits at lists.llvm.org> wrote:
>
> Author: vedantk
> Date: Wed May 30 16:35:14 2018
> New Revision: 333608
>
> URL: http://llvm.org/viewvc/llvm-project?rev=333608&view=rev
> Log:
> [llvm-cov] Use the new PrintHTMLEscaped utility
>
> This removes some duplicate logic to escape characters in HTML output.
>
> Modified:
> llvm/trunk/test/tools/llvm-cov/showTabsHTML.cpp
> llvm/trunk/tools/llvm-cov/SourceCoverageViewHTML.cpp
>
> Modified: llvm/trunk/test/tools/llvm-cov/showTabsHTML.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-cov/showTabsHTML.cpp?rev=333608&r1=333607&r2=333608&view=diff
> ==============================================================================
> --- llvm/trunk/test/tools/llvm-cov/showTabsHTML.cpp (original)
> +++ llvm/trunk/test/tools/llvm-cov/showTabsHTML.cpp Wed May 30 16:35:14 2018
> @@ -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";
>
> Modified: llvm/trunk/tools/llvm-cov/SourceCoverageViewHTML.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-cov/SourceCoverageViewHTML.cpp?rev=333608&r1=333607&r2=333608&view=diff
> ==============================================================================
> --- llvm/trunk/tools/llvm-cov/SourceCoverageViewHTML.cpp (original)
> +++ llvm/trunk/tools/llvm-cov/SourceCoverageViewHTML.cpp Wed May 30 16:35:14 2018
> @@ -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 += "<";
> - else if (C == '>')
> - Result += ">";
> - else if (C == '\"')
> - Result += """;
> - 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 += " ";
> + TabExpandedResult += ' ';
> ColNum += NumSpaces;
> - } else
> - Result += C;
> + } else {
> + TabExpandedResult += C;
> + if (C == '\n' || C == '\r')
> + ColNum = 0;
> + else
> + ++ColNum;
> + }
> }
> - return Result;
> + std::string EscapedHTML;
> + {
> + raw_string_ostream OS{EscapedHTML};
> + PrintHTMLEscaped(TabExpandedResult, OS);
> + }
> + return EscapedHTML;
> }
>
> // Create a \p Name tag around \p Str, and optionally set its \p ClassName.
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
More information about the llvm-commits
mailing list