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 | 1b580f98aacb3ad89d6e7e5431c00c1fa7577b2a (patch) | |
tree | 63387d0d09cb01ddcc2776b035907da6bca2efbd /clang | |
parent | 7dcc82220e8a618367489b1cdfdc6b52058c93f7 (diff) | |
download | bcm5719-llvm-1b580f98aacb3ad89d6e7e5431c00c1fa7577b2a.tar.gz bcm5719-llvm-1b580f98aacb3ad89d6e7e5431c00c1fa7577b2a.zip |
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).
llvm-svn: 48506
Diffstat (limited to 'clang')
-rw-r--r-- | clang/include/clang/Rewrite/HTMLRewrite.h | 3 | ||||
-rw-r--r-- | clang/lib/Rewrite/HTMLRewrite.cpp | 20 |
2 files changed, 19 insertions, 4 deletions
diff --git a/clang/include/clang/Rewrite/HTMLRewrite.h b/clang/include/clang/Rewrite/HTMLRewrite.h index 3270cddf595..43923ae3328 100644 --- a/clang/include/clang/Rewrite/HTMLRewrite.h +++ b/clang/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/clang/lib/Rewrite/HTMLRewrite.cpp b/clang/lib/Rewrite/HTMLRewrite.cpp index 3beede86970..717f6cec812 100644 --- a/clang/lib/Rewrite/HTMLRewrite.cpp +++ b/clang/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); } } |