Move the function to convert from xml_node to string in otherTools.

This can be usefull elsewhere than in opds_dumper
This commit is contained in:
Matthieu Gautier 2018-08-29 11:45:22 +02:00
parent f3dd83907d
commit 79b780b75b
3 changed files with 23 additions and 19 deletions

View File

@ -26,9 +26,12 @@
#include <unistd.h> #include <unistd.h>
#endif #endif
#include <pugixml.hpp>
namespace kiwix namespace kiwix
{ {
void sleep(unsigned int milliseconds); void sleep(unsigned int milliseconds);
std::string nodeToString(pugi::xml_node node);
} }
#endif #endif

View File

@ -27,3 +27,19 @@ void kiwix::sleep(unsigned int milliseconds)
usleep(1000 * milliseconds); usleep(1000 * milliseconds);
#endif #endif
} }
struct XmlStringWriter: pugi::xml_writer
{
std::string result;
virtual void write(const void* data, size_t size){
result.append(static_cast<const char*>(data), size);
}
};
std::string kiwix::nodeToString(pugi::xml_node node)
{
XmlStringWriter writer;
node.print(writer, " ");
return writer.result;
}

View File

@ -19,6 +19,9 @@
#include "opds_dumper.h" #include "opds_dumper.h"
#include <common/otherTools.h>
namespace kiwix namespace kiwix
{ {
/* Constructor */ /* Constructor */
@ -31,24 +34,6 @@ OPDSDumper::~OPDSDumper()
{ {
} }
struct xml_string_writer: pugi::xml_writer
{
std::string result;
virtual void write(const void* data, size_t size)
{
result.append(static_cast<const char*>(data), size);
}
};
std::string node_to_string(pugi::xml_node node)
{
xml_string_writer writer;
node.print(writer, " ");
return writer.result;
}
std::string gen_date_str() std::string gen_date_str()
{ {
auto now = time(0); auto now = time(0);
@ -129,7 +114,7 @@ string OPDSDumper::dumpOPDSFeed()
handleBook(book, root_node); handleBook(book, root_node);
} }
return node_to_string(root_node); return nodeToString(root_node);
} }
} }