XmlNode::to_string uses an ostringstream instead of a string
On my poor benchmark, it was infinitesimally faster.
This commit is contained in:
@@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
@@ -207,21 +208,21 @@ const std::string XmlNode::get_name() const
|
|||||||
|
|
||||||
std::string XmlNode::to_string() const
|
std::string XmlNode::to_string() const
|
||||||
{
|
{
|
||||||
std::string res("<");
|
std::ostringstream res;
|
||||||
res += this->name;
|
res << "<" << this->name;
|
||||||
for (const auto& it: this->attributes)
|
for (const auto& it: this->attributes)
|
||||||
res += " " + it.first + "='" + sanitize(it.second) + "'";
|
res << " " << it.first << "='" << sanitize(it.second) + "'";
|
||||||
if (!this->has_children() && this->inner.empty())
|
if (!this->has_children() && this->inner.empty())
|
||||||
res += "/>";
|
res << "/>";
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
res += ">" + sanitize(this->inner);
|
res << ">" + sanitize(this->inner);
|
||||||
for (const auto& child: this->children)
|
for (const auto& child: this->children)
|
||||||
res += child->to_string();
|
res << child->to_string();
|
||||||
res += "</" + this->get_name() + ">";
|
res << "</" << this->get_name() << ">";
|
||||||
}
|
}
|
||||||
res += sanitize(this->tail);
|
res << sanitize(this->tail);
|
||||||
return res;
|
return res.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool XmlNode::has_children() const
|
bool XmlNode::has_children() const
|
||||||
|
|||||||
Reference in New Issue
Block a user