Files
swift-mirror/include/swift/ReST/XMLUtils.h
Dmitri Hrybenko 021b5b4561 Comment to XML conversion: pass through block markup as HTML tags, for the lack
of better markup in current XML schema

I know this XML is probably as bad as XML can get, but at least it allows
clients to render some block markup.  I expect to replace this with some real
tags soon.


Swift SVN r16657
2014-04-22 17:15:46 +00:00

78 lines
1.7 KiB
C++

//===--- XMLUtils.h - Various XML utility routines ------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2015 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_REST_XML_UTILS_H
#define LLVM_REST_XML_UTILS_H
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/raw_ostream.h"
namespace llvm {
namespace rest {
// FIXME: copied from Clang's
// CommentASTToXMLConverter::appendToResultWithXMLEscaping
static inline void appendWithXMLEscaping(raw_ostream &OS, StringRef S) {
for (const char C : S) {
switch (C) {
case '&':
OS << "&amp;";
break;
case '<':
OS << "&lt;";
break;
case '>':
OS << "&gt;";
break;
case '"':
OS << "&quot;";
break;
case '\'':
OS << "&apos;";
break;
default:
OS << C;
break;
}
}
}
// FIXME: copied from Clang's
// CommentASTToXMLConverter::appendToResultWithCDATAEscaping
static inline void appendWithCDATAEscaping(raw_ostream &OS, StringRef S) {
if (S.empty())
return;
OS << "<![CDATA[";
while (!S.empty()) {
size_t Pos = S.find("]]>");
if (Pos == 0) {
OS << "]]]]><![CDATA[>";
S = S.drop_front(3);
continue;
}
if (Pos == StringRef::npos)
Pos = S.size();
OS << S.substr(0, Pos);
S = S.drop_front(Pos);
}
OS << "]]>";
}
} // namespace rest
} // namespace llvm
#endif // LLVM_REST_XML_UTILS_H