forked from OSchip/llvm-project
Add html::EscapeText for std::string; use this function to escape text in message bubbles.
llvm-svn: 48884
This commit is contained in:
parent
ed9f054a9c
commit
561dfe3153
|
@ -117,8 +117,8 @@ void HTMLDiagnostics::HandlePathDiagnostic(const PathDiagnostic& D) {
|
|||
std::ostringstream os;
|
||||
const FileEntry* Entry = SMgr.getFileEntryForID(FileID);
|
||||
|
||||
os << "<h1>" << Entry->getDir()->getName() << "/"
|
||||
<< Entry->getName() << "</h1>\n";
|
||||
os << "<h1>" << html::EscapeText(Entry->getDir()->getName())
|
||||
<< "/" << html::EscapeText(Entry->getName()) << "</h1>\n";
|
||||
|
||||
R.InsertStrBefore(SourceLocation::getFileLoc(FileID, 0), os.str());
|
||||
}
|
||||
|
@ -200,7 +200,7 @@ void HTMLDiagnostics::HandlePiece(Rewriter& R,
|
|||
<< "<div class=\"msg\" style=\"margin-left:"
|
||||
<< ColNo << "ex\">";
|
||||
|
||||
os << P.getString() << "</div></td></tr>";
|
||||
os << html::EscapeText(P.getString()) << "</div></td></tr>";
|
||||
|
||||
// Insert the new html.
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#define LLVM_CLANG_HTMLREWRITER_H
|
||||
|
||||
#include "clang/Basic/SourceLocation.h"
|
||||
#include <string>
|
||||
|
||||
namespace clang {
|
||||
|
||||
|
@ -24,7 +25,8 @@ class Rewriter;
|
|||
namespace html {
|
||||
|
||||
void EscapeText(Rewriter& R, unsigned FileID, bool EscapeSpaces = false);
|
||||
|
||||
std::string EscapeText(const std::string& s, bool EscapeSpaces = false);
|
||||
|
||||
void AddLineNumbers(Rewriter& R, unsigned FileID);
|
||||
|
||||
void AddHeaderFooterInternalBuiltinCSS(Rewriter& R, unsigned FileID);
|
||||
|
|
|
@ -46,6 +46,32 @@ void html::EscapeText(Rewriter& R, unsigned FileID, bool EscapeSpaces) {
|
|||
}
|
||||
}
|
||||
|
||||
std::string html::EscapeText(const std::string& s, bool EscapeSpaces) {
|
||||
|
||||
unsigned len = s.size();
|
||||
std::ostringstream os;
|
||||
|
||||
for (unsigned i = 0 ; i < len; ++i) {
|
||||
|
||||
char c = s[i];
|
||||
|
||||
switch (c) {
|
||||
default:
|
||||
os << c; break;
|
||||
|
||||
case ' ':
|
||||
if (EscapeSpaces) os << " ";
|
||||
break;
|
||||
|
||||
case '<': os << "<"; break;
|
||||
case '>': os << ">"; break;
|
||||
case '&': os << "&"; break;
|
||||
}
|
||||
}
|
||||
|
||||
return os.str();
|
||||
}
|
||||
|
||||
static void AddLineNumber(Rewriter& R, unsigned LineNo,
|
||||
SourceLocation B, SourceLocation E) {
|
||||
|
||||
|
|
Loading…
Reference in New Issue