diff options
author | Ted Kremenek <kremenek@apple.com> | 2008-03-18 21:26:34 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2008-03-18 21:26:34 +0000 |
commit | c22efea6f999e98733f3431db03b10ce619faa8b (patch) | |
tree | 4bca027d7b1f754d50808ed5b9be1bf0b30e9cf8 | |
parent | 6a34083e9f74a45e2f79c9fab66f177809a5db66 (diff) |
Modified "InsertTag" (HTML rewriter) to have an optional "OutermostTag" flag to
indicate whether or not the new tag should be the outermost tag at the specified
location (in the case that other tags have been inserted at the same spot).
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@48506 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/clang/Rewrite/HTMLRewrite.h | 3 | ||||
-rw-r--r-- | lib/Rewrite/HTMLRewrite.cpp | 20 |
2 files changed, 19 insertions, 4 deletions
diff --git a/include/clang/Rewrite/HTMLRewrite.h b/include/clang/Rewrite/HTMLRewrite.h index 3270cddf59..43923ae332 100644 --- a/include/clang/Rewrite/HTMLRewrite.h +++ b/include/clang/Rewrite/HTMLRewrite.h @@ -29,7 +29,8 @@ namespace html { void InsertTag(Rewriter& R, Tags tag, SourceLocation OpenLoc, SourceLocation CloseLoc, - bool NewlineOpen = false, bool NewlineClose = true); + bool NewlineOpen = false, bool NewlineClose = true, + bool OutermostTag = false); } // end html namespace } // end clang namespace diff --git a/lib/Rewrite/HTMLRewrite.cpp b/lib/Rewrite/HTMLRewrite.cpp index 3beede8697..717f6cec81 100644 --- a/lib/Rewrite/HTMLRewrite.cpp +++ b/lib/Rewrite/HTMLRewrite.cpp @@ -48,7 +48,7 @@ void html::EscapeText(Rewriter& R, unsigned FileID, bool EscapeSpaces) { void html::InsertTag(Rewriter& R, html::Tags tag, SourceLocation B, SourceLocation E, - bool NewlineOpen, bool NewlineClose) { + bool NewlineOpen, bool NewlineClose, bool OutermostTag) { const char* TagStr = 0; @@ -65,13 +65,27 @@ void html::InsertTag(Rewriter& R, html::Tags tag, std::ostringstream os; os << '<' << TagStr << '>'; if (NewlineOpen) os << '\n'; - R.InsertTextAfter(B, os.str().c_str(), os.str().size()); + + const char* s = os.str().c_str(); + unsigned n = os.str().size(); + + if (OutermostTag) + R.InsertTextBefore(B, s, n); + else + R.InsertTextAfter(B, s, n); } { // Generate the closing tag. std::ostringstream os; os << "</" << TagStr << '>'; if (NewlineClose) os << '\n'; - R.InsertTextBefore(E, os.str().c_str(), os.str().size()); + + const char* s = os.str().c_str(); + unsigned n = os.str().size(); + + if (OutermostTag) + R.InsertTextAfter(E, s, n); + else + R.InsertTextBefore(E, s, n); } } |