mirror of https://github.com/kiwix/libkiwix.git
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:
parent
f3dd83907d
commit
79b780b75b
|
@ -26,9 +26,12 @@
|
|||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include <pugixml.hpp>
|
||||
|
||||
namespace kiwix
|
||||
{
|
||||
void sleep(unsigned int milliseconds);
|
||||
std::string nodeToString(pugi::xml_node node);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -27,3 +27,19 @@ void kiwix::sleep(unsigned int milliseconds)
|
|||
usleep(1000 * milliseconds);
|
||||
#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;
|
||||
}
|
||||
|
|
|
@ -19,6 +19,9 @@
|
|||
|
||||
#include "opds_dumper.h"
|
||||
|
||||
|
||||
#include <common/otherTools.h>
|
||||
|
||||
namespace kiwix
|
||||
{
|
||||
/* 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()
|
||||
{
|
||||
auto now = time(0);
|
||||
|
@ -129,7 +114,7 @@ string OPDSDumper::dumpOPDSFeed()
|
|||
handleBook(book, root_node);
|
||||
}
|
||||
|
||||
return node_to_string(root_node);
|
||||
return nodeToString(root_node);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue