diff --git a/lib/Rewrite/HTMLRewrite.cpp b/lib/Rewrite/HTMLRewrite.cpp index 7fea7fa18f..c832eff46d 100644 --- a/lib/Rewrite/HTMLRewrite.cpp +++ b/lib/Rewrite/HTMLRewrite.cpp @@ -29,20 +29,40 @@ void html::EscapeText(Rewriter& R, unsigned FileID, bool EscapeSpaces) { assert (C <= FileEnd); for (unsigned FilePos = 0; C != FileEnd ; ++C, ++FilePos) { - - SourceLocation Loc = SourceLocation::getFileLoc(FileID, FilePos); - + switch (*C) { default: break; case ' ': - if (EscapeSpaces) R.ReplaceText(Loc, 1, " ", 6); + if (EscapeSpaces) { + SourceLocation Loc = SourceLocation::getFileLoc(FileID, FilePos); + R.ReplaceText(Loc, 1, " ", 6); + } break; - case '\t': R.ReplaceText(Loc, 1, " ", 6*4); break; - case '<': R.ReplaceText(Loc, 1, "<", 4); break; - case '>': R.ReplaceText(Loc, 1, ">", 4); break; - case '&': R.ReplaceText(Loc, 1, "&", 5); break; + case '\t': { + SourceLocation Loc = SourceLocation::getFileLoc(FileID, FilePos); + R.ReplaceText(Loc, 1, " ", 6*4); + break; + } + + case '<': { + SourceLocation Loc = SourceLocation::getFileLoc(FileID, FilePos); + R.ReplaceText(Loc, 1, "<", 4); + break; + } + + case '>': { + SourceLocation Loc = SourceLocation::getFileLoc(FileID, FilePos); + R.ReplaceText(Loc, 1, ">", 4); + break; + } + + case '&': { + SourceLocation Loc = SourceLocation::getFileLoc(FileID, FilePos); + R.ReplaceText(Loc, 1, "&", 5); + break; + } } } } @@ -78,28 +98,17 @@ std::string html::EscapeText(const std::string& s, bool EscapeSpaces) { static void AddLineNumber(Rewriter& R, unsigned LineNo, SourceLocation B, SourceLocation E) { - // Put the closing first. - - R.InsertCStrBefore(E, ""); - - if (B == E) // Handle empty lines. - R.InsertCStrBefore(B, "