diff options
Diffstat (limited to 'lib/Index/CommentToXML.cpp')
-rw-r--r-- | lib/Index/CommentToXML.cpp | 58 |
1 files changed, 47 insertions, 11 deletions
diff --git a/lib/Index/CommentToXML.cpp b/lib/Index/CommentToXML.cpp index 43c423274d..eb5a0c8363 100644 --- a/lib/Index/CommentToXML.cpp +++ b/lib/Index/CommentToXML.cpp @@ -563,6 +563,7 @@ public: // Helpers. void appendToResultWithXMLEscaping(StringRef S); + void appendToResultWithCDATAEscaping(StringRef S); void formatTextOfDeclaration(const DeclInfo *DI, SmallString<128> &Declaration); @@ -667,14 +668,27 @@ void CommentASTToXMLConverter::visitInlineCommandComment( void CommentASTToXMLConverter::visitHTMLStartTagComment( const HTMLStartTagComment *C) { - Result << "<rawHTML><![CDATA["; - printHTMLStartTagComment(C, Result); - Result << "]]></rawHTML>"; + Result << "<rawHTML"; + if (C->isSafeToPassThrough()) + Result << " isSafeToPassThrough=\"1\""; + Result << ">"; + { + SmallString<32> Tag; + { + llvm::raw_svector_ostream TagOS(Tag); + printHTMLStartTagComment(C, TagOS); + } + appendToResultWithCDATAEscaping(Tag); + } + Result << "</rawHTML>"; } void CommentASTToXMLConverter::visitHTMLEndTagComment(const HTMLEndTagComment *C) { - Result << "<rawHTML></" << C->getTagName() << "></rawHTML>"; + Result << "<rawHTML"; + if (C->isSafeToPassThrough()) + Result << " isSafeToPassThrough=\"1\""; + Result << "></" << C->getTagName() << "></rawHTML>"; } void @@ -1100,6 +1114,31 @@ void CommentASTToXMLConverter::appendToResultWithXMLEscaping(StringRef S) { } } +void CommentASTToXMLConverter::appendToResultWithCDATAEscaping(StringRef S) { + if (S.empty()) + return; + + Result << "<![CDATA["; + while (!S.empty()) { + size_t Pos = S.find("]]>"); + if (Pos == 0) { + Result << "]]]]><![CDATA[>"; + S = S.drop_front(3); + continue; + } + if (Pos == StringRef::npos) + Pos = S.size(); + + Result << S.substr(0, Pos); + + S = S.drop_front(Pos); + } + Result << "]]>"; +} + +CommentToXMLConverter::CommentToXMLConverter() : FormatInMemoryUniqueId(0) {} +CommentToXMLConverter::~CommentToXMLConverter() {} + void CommentToXMLConverter::convertCommentToHTML(const FullComment *FC, SmallVectorImpl<char> &HTML, const ASTContext &Context) { @@ -1119,13 +1158,10 @@ void CommentToXMLConverter::convertHTMLTagNodeToText( void CommentToXMLConverter::convertCommentToXML(const FullComment *FC, SmallVectorImpl<char> &XML, const ASTContext &Context) { - if (!FormatContext) { - FormatContext = new SimpleFormatContext(Context.getLangOpts()); - } else if ((FormatInMemoryUniqueId % 1000) == 0) { - // Delete after some number of iterations, so the buffers don't grow - // too large. - delete FormatContext; - FormatContext = new SimpleFormatContext(Context.getLangOpts()); + if (!FormatContext || (FormatInMemoryUniqueId % 1000) == 0) { + // Create a new format context, or re-create it after some number of + // iterations, so the buffers don't grow too large. + FormatContext.reset(new SimpleFormatContext(Context.getLangOpts())); } CommentASTToXMLConverter Converter(FC, XML, Context.getCommentCommandTraits(), |