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());
}
<< "<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.
#define LLVM_CLANG_HTMLREWRITER_H
#include "clang/Basic/SourceLocation.h"
+#include <string>
namespace clang {
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);
}
}
+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) {