]> git.sesse.net Git - xml-template/blobdiff - php5-swig/xml-template.swig
In php5-swig, replace the output_by_fd() hack with a function that allows conversion...
[xml-template] / php5-swig / xml-template.swig
index 225f8bbd2e2d9a4c17df0d3937bef0721a15beff..02314f0e81637b710b1adcebcff23ce52748a486 100644 (file)
@@ -1,4 +1,5 @@
 %module XML_Template_SWIG
+%include <std_string.i>
 
 struct XmlDocPtrWrapper {
        ~XmlDocPtrWrapper();
@@ -93,13 +94,31 @@ XmlDocPtrWrapper XML_Template_process_file(const char *input_filename, Directive
        delete root_directive;
        return XmlDocPtrWrapper(new XmlDocWrapper { ret });
 }
-       
-void output_to_fd(XmlDocPtrWrapper doc, int fd)
+
+namespace {
+
+int write_to_string(void *context, const char *buffer, int len)
 {
-       xmlOutputBufferPtr buf = xmlOutputBufferCreateFd(fd, NULL);
-       xmlSaveFileTo(buf, doc->ptr, NULL);
+       std::string *str = reinterpret_cast<std::string *>(context);
+       str->append(buffer, len);
+       return len;
+}
+
+int close_string(void *context)
+{
+       return 0;
 }
 
+}  // namespace
+
+std::string XML_Template_convert_doc_to_string(XmlDocPtrWrapper doc)
+{
+       std::string ret;
+       xmlOutputBufferPtr buf = xmlOutputBufferCreateIO(write_to_string, close_string, &ret, NULL);
+       xmlSaveFileTo(buf, doc->ptr, NULL);
+       return ret;
+}
+       
 %}
 
 %typemap(in) Directive* {
@@ -107,5 +126,5 @@ void output_to_fd(XmlDocPtrWrapper doc, int fd)
 }
 
 XmlDocPtrWrapper XML_Template_process_file(const char *input_filename, Directive *root_directive, bool clean);
-void output_to_fd(XmlDocPtrWrapper doc, int fd);
+std::string XML_Template_convert_doc_to_string(XmlDocPtrWrapper doc);