From 8ea2cd2814399ebce3b4a7f40a79b08a91cd7fff Mon Sep 17 00:00:00 2001 From: Jonas Devlieghere Date: Thu, 31 May 2018 17:01:42 +0000 Subject: [PATCH] [ADT] Make escaping fn conform to coding guidelines As noted by Adrian on llvm-commits, PrintHTMLEscaped and PrintEscaped in StringExtras did not conform to the LLVM coding guidelines. This commit rectifies that. llvm-svn: 333669 --- include/llvm/ADT/StringExtras.h | 8 ++++---- lib/CodeGen/MachineOperand.cpp | 2 +- lib/IR/AsmWriter.cpp | 24 +++++++++++------------ lib/IR/Attributes.cpp | 2 +- lib/Support/StringExtras.cpp | 4 ++-- tools/dsymutil/dsymutil.cpp | 6 +++--- tools/llvm-cov/SourceCoverageViewHTML.cpp | 2 +- unittests/ADT/StringExtrasTest.cpp | 4 ++-- 8 files changed, 26 insertions(+), 26 deletions(-) diff --git a/include/llvm/ADT/StringExtras.h b/include/llvm/ADT/StringExtras.h index 9af536c8822..21a1bbcfad2 100644 --- a/include/llvm/ADT/StringExtras.h +++ b/include/llvm/ADT/StringExtras.h @@ -251,13 +251,13 @@ inline StringRef getOrdinalSuffix(unsigned Val) { } } -/// PrintEscapedString - Print each character of the specified string, escaping -/// it if it is not printable or if it is an escape char. -void PrintEscapedString(StringRef Name, raw_ostream &Out); +/// Print each character of the specified string, escaping it if it is not +/// printable or if it is an escape char. +void printEscapedString(StringRef Name, raw_ostream &Out); /// Print each character of the specified string, escaping HTML special /// characters. -void PrintHTMLEscaped(StringRef String, raw_ostream &Out); +void printHTMLEscaped(StringRef String, raw_ostream &Out); /// printLowerCase - Print each character as lowercase if it is uppercase. void printLowerCase(StringRef String, raw_ostream &Out); diff --git a/lib/CodeGen/MachineOperand.cpp b/lib/CodeGen/MachineOperand.cpp index 2078a8bc6b0..8098333832b 100644 --- a/lib/CodeGen/MachineOperand.cpp +++ b/lib/CodeGen/MachineOperand.cpp @@ -474,7 +474,7 @@ static void printSyncScope(raw_ostream &OS, const LLVMContext &Context, Context.getSyncScopeNames(SSNs); OS << "syncscope(\""; - PrintEscapedString(SSNs[SSID], OS); + printEscapedString(SSNs[SSID], OS); OS << "\") "; break; } diff --git a/lib/IR/AsmWriter.cpp b/lib/IR/AsmWriter.cpp index 1212f8c7e4d..ba8db2bf41b 100644 --- a/lib/IR/AsmWriter.cpp +++ b/lib/IR/AsmWriter.cpp @@ -424,7 +424,7 @@ void llvm::printLLVMNameWithoutPrefix(raw_ostream &OS, StringRef Name) { // Okay, we need quotes. Output the quotes and escape any scary characters as // needed. OS << '"'; - PrintEscapedString(Name, OS); + printEscapedString(Name, OS); OS << '"'; } @@ -1377,7 +1377,7 @@ static void WriteConstantInternal(raw_ostream &Out, const Constant *CV, // i8 with ConstantInt values. if (CA->isString()) { Out << "c\""; - PrintEscapedString(CA->getAsString(), Out); + printEscapedString(CA->getAsString(), Out); Out << '"'; return; } @@ -1610,7 +1610,7 @@ void MDFieldPrinter::printString(StringRef Name, StringRef Value, return; Out << FS << Name << ": \""; - PrintEscapedString(Value, Out); + printEscapedString(Value, Out); Out << "\""; } @@ -2154,9 +2154,9 @@ static void WriteAsOperandInternal(raw_ostream &Out, const Value *V, if (IA->getDialect() == InlineAsm::AD_Intel) Out << "inteldialect "; Out << '"'; - PrintEscapedString(IA->getAsmString(), Out); + printEscapedString(IA->getAsmString(), Out); Out << "\", \""; - PrintEscapedString(IA->getConstraintString(), Out); + printEscapedString(IA->getConstraintString(), Out); Out << '"'; return; } @@ -2235,7 +2235,7 @@ static void WriteAsOperandInternal(raw_ostream &Out, const Metadata *MD, if (const MDString *MDS = dyn_cast(MD)) { Out << "!\""; - PrintEscapedString(MDS->getString(), Out); + printEscapedString(MDS->getString(), Out); Out << '"'; return; } @@ -2390,7 +2390,7 @@ void AssemblyWriter::writeSyncScope(const LLVMContext &Context, Context.getSyncScopeNames(SSNs); Out << " syncscope(\""; - PrintEscapedString(SSNs[SSID], Out); + printEscapedString(SSNs[SSID], Out); Out << "\")"; break; } @@ -2451,7 +2451,7 @@ void AssemblyWriter::writeOperandBundles(ImmutableCallSite CS) { FirstBundle = false; Out << '"'; - PrintEscapedString(BU.getTagName(), Out); + printEscapedString(BU.getTagName(), Out); Out << '"'; Out << '('; @@ -2487,7 +2487,7 @@ void AssemblyWriter::printModule(const Module *M) { if (!M->getSourceFileName().empty()) { Out << "source_filename = \""; - PrintEscapedString(M->getSourceFileName(), Out); + printEscapedString(M->getSourceFileName(), Out); Out << "\"\n"; } @@ -2509,7 +2509,7 @@ void AssemblyWriter::printModule(const Module *M) { // We found a newline, print the portion of the asm string from the // last newline up to this newline. Out << "module asm \""; - PrintEscapedString(Front, Out); + printEscapedString(Front, Out); Out << "\"\n"; } while (!Asm.empty()); } @@ -3143,7 +3143,7 @@ void AssemblyWriter::printGlobal(const GlobalVariable *GV) { if (GV->hasSection()) { Out << ", section \""; - PrintEscapedString(GV->getSection(), Out); + printEscapedString(GV->getSection(), Out); Out << '"'; } maybePrintComdat(Out, *GV); @@ -3327,7 +3327,7 @@ void AssemblyWriter::printFunction(const Function *F) { Out << " #" << Machine.getAttributeGroupSlot(Attrs.getFnAttributes()); if (F->hasSection()) { Out << " section \""; - PrintEscapedString(F->getSection(), Out); + printEscapedString(F->getSection(), Out); Out << '"'; } maybePrintComdat(Out, *F); diff --git a/lib/IR/Attributes.cpp b/lib/IR/Attributes.cpp index dbe38c2095d..01de8bb5627 100644 --- a/lib/IR/Attributes.cpp +++ b/lib/IR/Attributes.cpp @@ -419,7 +419,7 @@ std::string Attribute::getAsString(bool InAttrGrp) const { { raw_string_ostream OS(Result); OS << "=\""; - PrintEscapedString(AttrVal, OS); + printEscapedString(AttrVal, OS); OS << "\""; } return Result; diff --git a/lib/Support/StringExtras.cpp b/lib/Support/StringExtras.cpp index d8f8ff4f604..d566b72a8d0 100644 --- a/lib/Support/StringExtras.cpp +++ b/lib/Support/StringExtras.cpp @@ -58,7 +58,7 @@ void llvm::SplitString(StringRef Source, } } -void llvm::PrintEscapedString(StringRef Name, raw_ostream &Out) { +void llvm::printEscapedString(StringRef Name, raw_ostream &Out) { for (unsigned i = 0, e = Name.size(); i != e; ++i) { unsigned char C = Name[i]; if (isprint(C) && C != '\\' && C != '"') @@ -68,7 +68,7 @@ void llvm::PrintEscapedString(StringRef Name, raw_ostream &Out) { } } -void llvm::PrintHTMLEscaped(StringRef String, raw_ostream &Out) { +void llvm::printHTMLEscaped(StringRef String, raw_ostream &Out) { for (char C : String) { if (C == '&') Out << "&"; diff --git a/tools/dsymutil/dsymutil.cpp b/tools/dsymutil/dsymutil.cpp index 899c71e02d6..71e24cf610c 100644 --- a/tools/dsymutil/dsymutil.cpp +++ b/tools/dsymutil/dsymutil.cpp @@ -197,19 +197,19 @@ static bool createPlistFile(llvm::StringRef Bin, llvm::StringRef BundleRoot) { if (!BI.OmitShortVersion()) { PL << "\t\tCFBundleShortVersionString\n"; PL << "\t\t"; - PrintHTMLEscaped(BI.ShortVersionStr, PL); + printHTMLEscaped(BI.ShortVersionStr, PL); PL << "\n"; } PL << "\t\tCFBundleVersion\n"; PL << "\t\t"; - PrintHTMLEscaped(BI.VersionStr, PL); + printHTMLEscaped(BI.VersionStr, PL); PL << "\n"; if (!Toolchain.empty()) { PL << "\t\tToolchain\n"; PL << "\t\t"; - PrintHTMLEscaped(Toolchain, PL); + printHTMLEscaped(Toolchain, PL); PL << "\n"; } diff --git a/tools/llvm-cov/SourceCoverageViewHTML.cpp b/tools/llvm-cov/SourceCoverageViewHTML.cpp index 330da8bd8b7..acb67aa5cfc 100644 --- a/tools/llvm-cov/SourceCoverageViewHTML.cpp +++ b/tools/llvm-cov/SourceCoverageViewHTML.cpp @@ -45,7 +45,7 @@ std::string escape(StringRef Str, const CoverageViewOptions &Opts) { std::string EscapedHTML; { raw_string_ostream OS{EscapedHTML}; - PrintHTMLEscaped(TabExpandedResult, OS); + printHTMLEscaped(TabExpandedResult, OS); } return EscapedHTML; } diff --git a/unittests/ADT/StringExtrasTest.cpp b/unittests/ADT/StringExtrasTest.cpp index 87a4c2a389f..f98f388f64f 100644 --- a/unittests/ADT/StringExtrasTest.cpp +++ b/unittests/ADT/StringExtrasTest.cpp @@ -93,9 +93,9 @@ TEST(StringExtrasTest, printLowerCase) { EXPECT_EQ("abcdefg01234.,&!~`'}\"", OS.str()); } -TEST(StringExtrasTest, PrintHTMLEscaped) { +TEST(StringExtrasTest, printHTMLEscaped) { std::string str; raw_string_ostream OS(str); - PrintHTMLEscaped("ABCdef123&<>\"'", OS); + printHTMLEscaped("ABCdef123&<>\"'", OS); EXPECT_EQ("ABCdef123&<>"'", OS.str()); }