mirror of
https://github.com/catchorg/Catch2.git
synced 2025-09-17 02:25:38 +02:00
Refactored XMLWriter to provide finer-grained control over formatting
This commit is contained in:
@@ -14,6 +14,14 @@
|
||||
#include <vector>
|
||||
|
||||
namespace Catch {
|
||||
enum class XmlFormatting {
|
||||
None = 0x00,
|
||||
Indent = 0x01,
|
||||
Newline = 0x02,
|
||||
};
|
||||
|
||||
XmlFormatting operator | (XmlFormatting lhs, XmlFormatting rhs);
|
||||
XmlFormatting operator & (XmlFormatting lhs, XmlFormatting rhs);
|
||||
|
||||
class XmlEncode {
|
||||
public:
|
||||
@@ -35,14 +43,14 @@ namespace Catch {
|
||||
|
||||
class ScopedElement {
|
||||
public:
|
||||
ScopedElement( XmlWriter* writer );
|
||||
ScopedElement( XmlWriter* writer, XmlFormatting fmt );
|
||||
|
||||
ScopedElement( ScopedElement&& other ) noexcept;
|
||||
ScopedElement& operator=( ScopedElement&& other ) noexcept;
|
||||
|
||||
~ScopedElement();
|
||||
|
||||
ScopedElement& writeText( std::string const& text, bool indent = true );
|
||||
ScopedElement& writeText( std::string const& text, XmlFormatting fmt = XmlFormatting::Newline | XmlFormatting::Indent );
|
||||
|
||||
template<typename T>
|
||||
ScopedElement& writeAttribute( std::string const& name, T const& attribute ) {
|
||||
@@ -52,6 +60,7 @@ namespace Catch {
|
||||
|
||||
private:
|
||||
mutable XmlWriter* m_writer = nullptr;
|
||||
XmlFormatting m_fmt;
|
||||
};
|
||||
|
||||
XmlWriter( std::ostream& os = Catch::cout() );
|
||||
@@ -60,11 +69,11 @@ namespace Catch {
|
||||
XmlWriter( XmlWriter const& ) = delete;
|
||||
XmlWriter& operator=( XmlWriter const& ) = delete;
|
||||
|
||||
XmlWriter& startElement( std::string const& name );
|
||||
XmlWriter& startElement( std::string const& name, XmlFormatting fmt = XmlFormatting::Newline | XmlFormatting::Indent);
|
||||
|
||||
ScopedElement scopedElement( std::string const& name );
|
||||
ScopedElement scopedElement( std::string const& name, XmlFormatting fmt = XmlFormatting::Newline | XmlFormatting::Indent);
|
||||
|
||||
XmlWriter& endElement();
|
||||
XmlWriter& endElement(XmlFormatting fmt = XmlFormatting::Newline | XmlFormatting::Indent);
|
||||
|
||||
XmlWriter& writeAttribute( std::string const& name, std::string const& attribute );
|
||||
|
||||
@@ -77,9 +86,9 @@ namespace Catch {
|
||||
return writeAttribute( name, rss.str() );
|
||||
}
|
||||
|
||||
XmlWriter& writeText( std::string const& text, bool indent = true );
|
||||
XmlWriter& writeText( std::string const& text, XmlFormatting fmt = XmlFormatting::Newline | XmlFormatting::Indent);
|
||||
|
||||
XmlWriter& writeComment( std::string const& text );
|
||||
XmlWriter& writeComment(std::string const& text, XmlFormatting fmt = XmlFormatting::Newline | XmlFormatting::Indent);
|
||||
|
||||
void writeStylesheetRef( std::string const& url );
|
||||
|
||||
@@ -89,6 +98,8 @@ namespace Catch {
|
||||
|
||||
private:
|
||||
|
||||
void applyFormatting(XmlFormatting fmt);
|
||||
|
||||
void writeDeclaration();
|
||||
|
||||
void newlineIfNecessary();
|
||||
|
Reference in New Issue
Block a user