clang-format: Basic escaping when outputting XML.

llvm-svn: 250440
This commit is contained in:
Daniel Jasper 2015-10-15 18:39:31 +00:00
parent b860289dbd
commit f39757d0c0
1 changed files with 9 additions and 1 deletions

View File

@ -199,9 +199,11 @@ static bool fillRanges(MemoryBuffer *Code,
}
static void outputReplacementXML(StringRef Text) {
// FIXME: When we sort includes, we need to make sure the stream is correct
// utf-8.
size_t From = 0;
size_t Index;
while ((Index = Text.find_first_of("\n\r", From)) != StringRef::npos) {
while ((Index = Text.find_first_of("\n\r<&", From)) != StringRef::npos) {
llvm::outs() << Text.substr(From, Index - From);
switch (Text[Index]) {
case '\n':
@ -210,6 +212,12 @@ static void outputReplacementXML(StringRef Text) {
case '\r':
llvm::outs() << "&#13;";
break;
case '<':
llvm::outs() << "&lt;";
break;
case '&':
llvm::outs() << "&amp;";
break;
default:
llvm_unreachable("Unexpected character encountered!");
}