aboutsummaryrefslogtreecommitdiff
path: root/lib/Rewrite/HTMLRewrite.cpp
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2008-03-19 01:30:02 +0000
committerTed Kremenek <kremenek@apple.com>2008-03-19 01:30:02 +0000
commitf830997de6ca8aa9526a9f4bb44593c19040ca85 (patch)
tree72e222942cee969e3b1ea08bbab85a3f1c8073f2 /lib/Rewrite/HTMLRewrite.cpp
parent1b3188cfc2bfaeb14d40c43c1df62097b79016d1 (diff)
More cleanups to HTML rewriter API: remove the InsertTag method; was too complicated
and clients can achieve a cleaner design just by inserting tags directly. Reserve the "html" namespace for meta-level operations (e.g., escaping text, etc.) git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@48524 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Rewrite/HTMLRewrite.cpp')
-rw-r--r--lib/Rewrite/HTMLRewrite.cpp84
1 files changed, 8 insertions, 76 deletions
diff --git a/lib/Rewrite/HTMLRewrite.cpp b/lib/Rewrite/HTMLRewrite.cpp
index 79fff28854..32d20dfa04 100644
--- a/lib/Rewrite/HTMLRewrite.cpp
+++ b/lib/Rewrite/HTMLRewrite.cpp
@@ -20,10 +20,6 @@
using namespace clang;
-//===----------------------------------------------------------------------===//
-// Basic operations.
-//===----------------------------------------------------------------------===//
-
void html::EscapeText(Rewriter& R, unsigned FileID, bool EscapeSpaces) {
const llvm::MemoryBuffer *Buf = R.getSourceMgr().getBuffer(FileID);
@@ -50,83 +46,19 @@ void html::EscapeText(Rewriter& R, unsigned FileID, bool EscapeSpaces) {
}
}
-
-static void TagOpen(Rewriter& R, const char* TagStr,
- const char* Attr, const char* Content,
- SourceLocation L, bool InsertBefore) {
-
- std::ostringstream os;
- os << '<' << TagStr;
- if (Attr) os << ' ' << Attr;
- os << '>';
- if (Content) os << Content;
-
- if (InsertBefore)
- R.InsertTextBefore(L, os.str().c_str(), os.str().size());
- else
- R.InsertTextAfter(L, os.str().c_str(), os.str().size());
-}
-
-static void TagClose(Rewriter& R, const char* TagStr, SourceLocation L,
- bool Newline, bool InsertBefore) {
-
- std::ostringstream os;
- os << "</" << TagStr << ">";
- if (Newline) os << '\n';
-
- if (InsertBefore)
- R.InsertTextBefore(L, os.str().c_str(), os.str().size());
- else
- R.InsertTextAfter(L, os.str().c_str(), os.str().size());
-}
-
-void html::InsertTag(Rewriter& R, html::Tags tag,
- SourceLocation B, SourceLocation E,
- const char* Attr, const char* Content, bool Newline,
- bool OpenInsertBefore, bool CloseInsertBefore) {
-
- const char* TagStr = 0;
-
- switch (tag) {
- default: break;
- case BODY: TagStr = "body"; break;
- case DIV: TagStr = "div"; break;
- case HEAD: TagStr = "head"; break;
- case HTML: TagStr = "html"; break;
- case PRE: TagStr = "pre"; break;
- case SPAN: TagStr = "span"; break;
- case STYLE: TagStr = "style"; break;
- }
-
- assert (TagStr && "Tag not supported.");
-
- // Generate the opening tag. We also generate the closing
- // tag of the start and end SourceLocations are the same.
-
- if (OpenInsertBefore) {
- TagClose(R, TagStr, E, Newline, CloseInsertBefore);
- TagOpen(R, TagStr, Attr, Content, B, true);
- }
- else {
- TagOpen(R, TagStr, Attr, Content, B, false);
- TagClose(R, TagStr, E, Newline, true);
- }
-}
-
-//===----------------------------------------------------------------------===//
-// High-level operations.
-//===----------------------------------------------------------------------===//
-
static void AddLineNumber(Rewriter& R, unsigned LineNo,
SourceLocation B, SourceLocation E) {
+
+ // Surround the line with a span tag.
+
+ R.InsertTextBefore(E, "</span>", 7);
+ R.InsertTextBefore(B, "<span style=lines>", 18);
- // Add two "div" tags: one to contain the line number, and the other
- // to contain the content of the line.
+ // Insert a span tag for the line number.
std::ostringstream os;
- os << LineNo;
- html::InsertTag(R, html::SPAN, B, E, "style=lines");
- html::InsertTag(R, html::SPAN, B, B, "style=nums", os.str().c_str());
+ os << "<span style=nums>" << LineNo << "</span>";
+ R.InsertTextBefore(B, os.str().c_str(), os.str().size());
}
void html::AddLineNumbers(Rewriter& R, unsigned FileID) {