Commit 4e89a1be authored by Tiago Peixoto's avatar Tiago Peixoto
Browse files

Slightly improve xml escaping of strings

parent b3212a66
...@@ -13,18 +13,20 @@ ...@@ -13,18 +13,20 @@
#include <expat.h> #include <expat.h>
#include <boost/graph/graphml.hpp> #include <boost/graph/graphml.hpp>
#include <boost/algorithm/string/replace.hpp> #include <boost/algorithm/string/replace.hpp>
#include <boost/archive/iterators/xml_escape.hpp>
#include <boost/archive/iterators/ostream_iterator.hpp>
using namespace boost; using namespace boost;
namespace boost namespace boost
{ {
std::string protect_xml_string(const std::string& os) std::string protect_xml_string(const std::string& os)
{ {
using namespace boost::algorithm; using namespace boost::archive::iterators;
std::string s(os); std::stringstream s;
replace_all(s, "&", "&amp;"); std::copy(xml_escape<const char*>(os.c_str()),
replace_all(s, "<", "&lt;"); xml_escape<const char*>(os.c_str()+os.size()),
replace_all(s, ">", "&gt;"); ostream_iterator<char>(s));
return s; return s.str();
} }
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment