mirror of
https://github.com/catchorg/Catch2.git
synced 2024-12-23 11:43:29 +01:00
Use StringRef in XmLWriter when the text is not stored
This commit is contained in:
parent
1d04427fcd
commit
c7241bb76e
@ -267,18 +267,19 @@ namespace {
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
XmlWriter& XmlWriter::writeAttribute( std::string const& name, std::string const& attribute ) {
|
XmlWriter& XmlWriter::writeAttribute( StringRef name,
|
||||||
|
StringRef attribute ) {
|
||||||
if( !name.empty() && !attribute.empty() )
|
if( !name.empty() && !attribute.empty() )
|
||||||
m_os << ' ' << name << "=\"" << XmlEncode( attribute, XmlEncode::ForAttributes ) << '"';
|
m_os << ' ' << name << "=\"" << XmlEncode( attribute, XmlEncode::ForAttributes ) << '"';
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
XmlWriter& XmlWriter::writeAttribute( std::string const& name, bool attribute ) {
|
XmlWriter& XmlWriter::writeAttribute( StringRef name, bool attribute ) {
|
||||||
m_os << ' ' << name << "=\"" << ( attribute ? "true" : "false" ) << '"';
|
m_os << ' ' << name << "=\"" << ( attribute ? "true" : "false" ) << '"';
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
XmlWriter& XmlWriter::writeText( std::string const& text, XmlFormatting fmt) {
|
XmlWriter& XmlWriter::writeText( StringRef text, XmlFormatting fmt ) {
|
||||||
if( !text.empty() ){
|
if( !text.empty() ){
|
||||||
bool tagWasOpen = m_tagIsOpen;
|
bool tagWasOpen = m_tagIsOpen;
|
||||||
ensureTagClosed();
|
ensureTagClosed();
|
||||||
@ -291,7 +292,7 @@ namespace {
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
XmlWriter& XmlWriter::writeComment( std::string const& text, XmlFormatting fmt) {
|
XmlWriter& XmlWriter::writeComment( StringRef text, XmlFormatting fmt ) {
|
||||||
ensureTagClosed();
|
ensureTagClosed();
|
||||||
if (shouldIndent(fmt)) {
|
if (shouldIndent(fmt)) {
|
||||||
m_os << m_indent;
|
m_os << m_indent;
|
||||||
@ -301,7 +302,7 @@ namespace {
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
void XmlWriter::writeStylesheetRef( std::string const& url ) {
|
void XmlWriter::writeStylesheetRef( StringRef url ) {
|
||||||
m_os << R"(<?xml-stylesheet type="text/xsl" href=")" << url << R"("?>)" << '\n';
|
m_os << R"(<?xml-stylesheet type="text/xsl" href=")" << url << R"("?>)" << '\n';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,22 +81,32 @@ namespace Catch {
|
|||||||
|
|
||||||
XmlWriter& endElement(XmlFormatting fmt = XmlFormatting::Newline | XmlFormatting::Indent);
|
XmlWriter& endElement(XmlFormatting fmt = XmlFormatting::Newline | XmlFormatting::Indent);
|
||||||
|
|
||||||
XmlWriter& writeAttribute( std::string const& name, std::string const& attribute );
|
//! The attribute content is XML-encoded
|
||||||
|
XmlWriter& writeAttribute( StringRef name, StringRef attribute );
|
||||||
|
|
||||||
XmlWriter& writeAttribute( std::string const& name, bool attribute );
|
//! Writes the attribute as "true/false"
|
||||||
|
XmlWriter& writeAttribute( StringRef name, bool attribute );
|
||||||
|
|
||||||
|
//! The attribute value must provide op<<(ostream&, T). Resulting
|
||||||
|
//! serialization is XML-encoded
|
||||||
template<typename T>
|
template<typename T>
|
||||||
XmlWriter& writeAttribute( std::string const& name, T const& attribute ) {
|
XmlWriter& writeAttribute( StringRef name, T const& attribute ) {
|
||||||
ReusableStringStream rss;
|
ReusableStringStream rss;
|
||||||
rss << attribute;
|
rss << attribute;
|
||||||
return writeAttribute( name, rss.str() );
|
// We need to explicitly convert the string to StringRef to
|
||||||
|
// guarantee the right overload is picked
|
||||||
|
return writeAttribute( name, StringRef(rss.str()) );
|
||||||
}
|
}
|
||||||
|
|
||||||
XmlWriter& writeText( std::string const& text, XmlFormatting fmt = XmlFormatting::Newline | XmlFormatting::Indent);
|
XmlWriter& writeText( StringRef text,
|
||||||
|
XmlFormatting fmt = XmlFormatting::Newline |
|
||||||
|
XmlFormatting::Indent );
|
||||||
|
|
||||||
XmlWriter& writeComment(std::string const& text, XmlFormatting fmt = XmlFormatting::Newline | XmlFormatting::Indent);
|
XmlWriter& writeComment( StringRef text,
|
||||||
|
XmlFormatting fmt = XmlFormatting::Newline |
|
||||||
|
XmlFormatting::Indent );
|
||||||
|
|
||||||
void writeStylesheetRef( std::string const& url );
|
void writeStylesheetRef( StringRef url );
|
||||||
|
|
||||||
XmlWriter& writeBlankLine();
|
XmlWriter& writeBlankLine();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user