"
<< LineNo << " | ";
if (B == E) { // Handle empty lines.
OS << " |
";
RB.InsertTextBefore(B, OS.str());
} else {
RB.InsertTextBefore(B, OS.str());
RB.InsertTextBefore(E, "");
}
}
void html::AddLineNumbers(Rewriter& R, FileID FID) {
const llvm::MemoryBuffer *Buf = R.getSourceMgr().getBuffer(FID);
const char* FileBeg = Buf->getBufferStart();
const char* FileEnd = Buf->getBufferEnd();
const char* C = FileBeg;
RewriteBuffer &RB = R.getEditBuffer(FID);
assert (C <= FileEnd);
unsigned LineNo = 0;
unsigned FilePos = 0;
while (C != FileEnd) {
++LineNo;
unsigned LineStartPos = FilePos;
unsigned LineEndPos = FileEnd - FileBeg;
assert (FilePos <= LineEndPos);
assert (C < FileEnd);
// Scan until the newline (or end-of-file).
while (C != FileEnd) {
char c = *C;
++C;
if (c == '\n') {
LineEndPos = FilePos++;
break;
}
++FilePos;
}
AddLineNumber(RB, LineNo, LineStartPos, LineEndPos);
}
// Add one big table tag that surrounds all of the code.
RB.InsertTextBefore(0, "