llvm.org GIT mirror llvm / 7eeba25
[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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@333669 91177308-0d34-0410-b5e6-96231b3b80d8 Jonas Devlieghere 1 year, 11 months ago
8 changed file(s) with 26 addition(s) and 26 deletion(s). Raw diff Collapse all Expand all
250250 }
251251 }
252252
253 /// PrintEscapedString - Print each character of the specified string, escaping
254 /// it if it is not printable or if it is an escape char.
255 void PrintEscapedString(StringRef Name, raw_ostream &Out);
253 /// Print each character of the specified string, escaping it if it is not
254 /// printable or if it is an escape char.
255 void printEscapedString(StringRef Name, raw_ostream &Out);
256256
257257 /// Print each character of the specified string, escaping HTML special
258258 /// characters.
259 void PrintHTMLEscaped(StringRef String, raw_ostream &Out);
259 void printHTMLEscaped(StringRef String, raw_ostream &Out);
260260
261261 /// printLowerCase - Print each character as lowercase if it is uppercase.
262262 void printLowerCase(StringRef String, raw_ostream &Out);
473473 Context.getSyncScopeNames(SSNs);
474474
475475 OS << "syncscope(\"";
476 PrintEscapedString(SSNs[SSID], OS);
476 printEscapedString(SSNs[SSID], OS);
477477 OS << "\") ";
478478 break;
479479 }
423423 // Okay, we need quotes. Output the quotes and escape any scary characters as
424424 // needed.
425425 OS << '"';
426 PrintEscapedString(Name, OS);
426 printEscapedString(Name, OS);
427427 OS << '"';
428428 }
429429
13761376 // i8 with ConstantInt values.
13771377 if (CA->isString()) {
13781378 Out << "c\"";
1379 PrintEscapedString(CA->getAsString(), Out);
1379 printEscapedString(CA->getAsString(), Out);
13801380 Out << '"';
13811381 return;
13821382 }
16091609 return;
16101610
16111611 Out << FS << Name << ": \"";
1612 PrintEscapedString(Value, Out);
1612 printEscapedString(Value, Out);
16131613 Out << "\"";
16141614 }
16151615
21532153 if (IA->getDialect() == InlineAsm::AD_Intel)
21542154 Out << "inteldialect ";
21552155 Out << '"';
2156 PrintEscapedString(IA->getAsmString(), Out);
2156 printEscapedString(IA->getAsmString(), Out);
21572157 Out << "\", \"";
2158 PrintEscapedString(IA->getConstraintString(), Out);
2158 printEscapedString(IA->getConstraintString(), Out);
21592159 Out << '"';
21602160 return;
21612161 }
22342234
22352235 if (const MDString *MDS = dyn_cast(MD)) {
22362236 Out << "!\"";
2237 PrintEscapedString(MDS->getString(), Out);
2237 printEscapedString(MDS->getString(), Out);
22382238 Out << '"';
22392239 return;
22402240 }
23892389 Context.getSyncScopeNames(SSNs);
23902390
23912391 Out << " syncscope(\"";
2392 PrintEscapedString(SSNs[SSID], Out);
2392 printEscapedString(SSNs[SSID], Out);
23932393 Out << "\")";
23942394 break;
23952395 }
24502450 FirstBundle = false;
24512451
24522452 Out << '"';
2453 PrintEscapedString(BU.getTagName(), Out);
2453 printEscapedString(BU.getTagName(), Out);
24542454 Out << '"';
24552455
24562456 Out << '(';
24862486
24872487 if (!M->getSourceFileName().empty()) {
24882488 Out << "source_filename = \"";
2489 PrintEscapedString(M->getSourceFileName(), Out);
2489 printEscapedString(M->getSourceFileName(), Out);
24902490 Out << "\"\n";
24912491 }
24922492
25082508 // We found a newline, print the portion of the asm string from the
25092509 // last newline up to this newline.
25102510 Out << "module asm \"";
2511 PrintEscapedString(Front, Out);
2511 printEscapedString(Front, Out);
25122512 Out << "\"\n";
25132513 } while (!Asm.empty());
25142514 }
31423142
31433143 if (GV->hasSection()) {
31443144 Out << ", section \"";
3145 PrintEscapedString(GV->getSection(), Out);
3145 printEscapedString(GV->getSection(), Out);
31463146 Out << '"';
31473147 }
31483148 maybePrintComdat(Out, *GV);
33263326 Out << " #" << Machine.getAttributeGroupSlot(Attrs.getFnAttributes());
33273327 if (F->hasSection()) {
33283328 Out << " section \"";
3329 PrintEscapedString(F->getSection(), Out);
3329 printEscapedString(F->getSection(), Out);
33303330 Out << '"';
33313331 }
33323332 maybePrintComdat(Out, *F);
418418 {
419419 raw_string_ostream OS(Result);
420420 OS << "=\"";
421 PrintEscapedString(AttrVal, OS);
421 printEscapedString(AttrVal, OS);
422422 OS << "\"";
423423 }
424424 return Result;
5757 }
5858 }
5959
60 void llvm::PrintEscapedString(StringRef Name, raw_ostream &Out) {
60 void llvm::printEscapedString(StringRef Name, raw_ostream &Out) {
6161 for (unsigned i = 0, e = Name.size(); i != e; ++i) {
6262 unsigned char C = Name[i];
6363 if (isprint(C) && C != '\\' && C != '"')
6767 }
6868 }
6969
70 void llvm::PrintHTMLEscaped(StringRef String, raw_ostream &Out) {
70 void llvm::printHTMLEscaped(StringRef String, raw_ostream &Out) {
7171 for (char C : String) {
7272 if (C == '&')
7373 Out << "&";
196196 if (!BI.OmitShortVersion()) {
197197 PL << "\t\tCFBundleShortVersionString\n";
198198 PL << "\t\t";
199 PrintHTMLEscaped(BI.ShortVersionStr, PL);
199 printHTMLEscaped(BI.ShortVersionStr, PL);
200200 PL << "\n";
201201 }
202202
203203 PL << "\t\tCFBundleVersion\n";
204204 PL << "\t\t";
205 PrintHTMLEscaped(BI.VersionStr, PL);
205 printHTMLEscaped(BI.VersionStr, PL);
206206 PL << "\n";
207207
208208 if (!Toolchain.empty()) {
209209 PL << "\t\tToolchain\n";
210210 PL << "\t\t";
211 PrintHTMLEscaped(Toolchain, PL);
211 printHTMLEscaped(Toolchain, PL);
212212 PL << "\n";
213213 }
214214
4444 std::string EscapedHTML;
4545 {
4646 raw_string_ostream OS{EscapedHTML};
47 PrintHTMLEscaped(TabExpandedResult, OS);
47 printHTMLEscaped(TabExpandedResult, OS);
4848 }
4949 return EscapedHTML;
5050 }
9292 EXPECT_EQ("abcdefg01234.,&!~`'}\"", OS.str());
9393 }
9494
95 TEST(StringExtrasTest, PrintHTMLEscaped) {
95 TEST(StringExtrasTest, printHTMLEscaped) {
9696 std::string str;
9797 raw_string_ostream OS(str);
98 PrintHTMLEscaped("ABCdef123&<>\"'", OS);
98 printHTMLEscaped("ABCdef123&<>\"'", OS);
9999 EXPECT_EQ("ABCdef123&<>"'", OS.str());
100100 }