]> git.sesse.net Git - xml-template/commitdiff
In php5-swig, replace the output_by_fd() hack with a function that allows conversion...
authorsgunderson@bigfoot.com <>
Fri, 23 Sep 2011 21:39:30 +0000 (23:39 +0200)
committersgunderson@bigfoot.com <>
Fri, 23 Sep 2011 21:39:30 +0000 (23:39 +0200)
12 files changed:
php5-swig/attribute-empty.php
php5-swig/attribute.php
php5-swig/attribute2.php
php5-swig/attribute3.php
php5-swig/clone.php
php5-swig/include.php
php5-swig/namespace.php
php5-swig/namespace2.php
php5-swig/passthru.php
php5-swig/simple.php
php5-swig/structure.php
php5-swig/xml-template.swig

index ba4941ec384e0101fa3af5b623749813fc2aa3e4..ce4e532ecfdc716789ccbc4888cbe247ae52cf35 100644 (file)
@@ -8,5 +8,5 @@ $doc = XML_Template_process_file('../xml/clone.xml', array(
        'color' => 'blue',
        '#things' => array(NULL)
 ), true);
-output_to_fd($doc, 1);
+print XML_Template_convert_doc_to_string($doc);
 ?>
index cc0656148159d1f3f3325e2ec3153711851f2402..8087dc7adfce9229b75b9a3e7a8d4b1d89ef8163 100644 (file)
@@ -10,5 +10,5 @@ $doc = XML_Template_process_file('../xml/clone.xml', array(
                array( 'li' => 'Warm, woolen mittens',  'li/class' => 'even' )
        )
 ), true);
-output_to_fd($doc, 1);
+print XML_Template_convert_doc_to_string($doc);
 ?>
index 95a6970bd19c0cb376085f908dfe67ad3653553a..8d6c99bd5577017b7e639988cf243a3771aaa1ee 100644 (file)
@@ -10,5 +10,5 @@ $doc = XML_Template_process_file('../xml/clone.xml', array(
                array( 'li' => 'Warm, woolen mittens' ),
        ), array('odd', 'even'))
 ), true);
-output_to_fd($doc, 1);
+print XML_Template_convert_doc_to_string($doc);
 ?>
index 74920fd72172d67279d7993d5f91b7b7263c50a4..1262a906b897aa8f82b3b5830f25cb559ae546e6 100644 (file)
@@ -11,5 +11,5 @@ $doc = XML_Template_process_file('../xml/clone.xml', array(
                array( 'li' => 'Warm, woolen mittens' ),
        ), array('odd', 'even'))
 ), true);
-output_to_fd($doc, 1);
+print XML_Template_convert_doc_to_string($doc);
 ?>
index ab0ed7a31e4d73aebb06a497fdd9c2d2f57456cc..20444db54ebfd4147f5cc5110aef4da50e63384a 100644 (file)
@@ -10,7 +10,7 @@ $doc = XML_Template_process_file('../xml/clone.xml', array(
                array( 'li' => 'Warm, woolen mittens' ) 
        )
 ), true);
-output_to_fd($doc, 1);
+print XML_Template_convert_doc_to_string($doc);
 
 ?>
 
index cc98dde7bfe15a924f5f53dd3c4ac132b6e8d28f..69ee5132bcd86f0f5dea18bdd7bd4a95a4179e27 100644 (file)
@@ -9,5 +9,5 @@ $master = XML_Template_process_file('../xml/master.xml', array(
        'h1' => 'Nice heading here',
        'contents' => $doc
 ), true);
-output_to_fd($master, 1);
+print XML_Template_convert_doc_to_string($master);
 ?>
index b5c854705359d8661df09e7f1a78677f65595dee..04d2faccf5108462dee39c6b13db6d7bb14353de 100644 (file)
@@ -8,5 +8,5 @@ $doc = XML_Template_process_file('../xml/namespace.xml', array(
        'tagname' => 'foo',
        '#moretest' => 'bar'
 ), true);
-output_to_fd($doc, 1);
+print XML_Template_convert_doc_to_string($doc);
 ?>
index 3111890dc710c2edbbbeaffe85f0bb8d85165ea5..998cf6646d516c579c0f078a4ef7141427853d5f 100644 (file)
@@ -5,5 +5,5 @@ $doc = XML_Template_process_file('../xml/namespace2.xml', array(
        'title' => 'Namespace tests',
        '#hello' => 'Replaced.',
 ), true);
-output_to_fd($doc, 1);
+print XML_Template_convert_doc_to_string($doc);
 ?>
index c51e1e1f60787011815678f7f83952c8014c354a..91f1f56bddae6d385764918744d2c23bbc98e36b 100644 (file)
@@ -2,7 +2,7 @@
 include("xml-template.php");
 
 $doc = XML_Template_process_file('../xml/passthru.xml', array(), true);
-output_to_fd($doc, 1);
+print XML_Template_convert_doc_to_string($doc);
 
 ?>
 
index 33a512d8711645586a618e5c93863b8c5f264f37..7e6ce848ca79222eae58d7404ee5b8f13285304c 100644 (file)
@@ -5,7 +5,7 @@ $doc = XML_Template_process_file('../xml/simple.xml', array(
        'title' => 'A very basic example',
        '#hello' => 'Hello world!'
 ), true);
-output_to_fd($doc, 1);
+print XML_Template_convert_doc_to_string($doc);
 
 ?>
 
index 32399ddddf461a7362bcd53260b579a6b52883f2..de2e3ab8aeffecc0108941679699c78c2f313945 100644 (file)
@@ -8,5 +8,5 @@ $doc = XML_Template_process_file('../xml/structure.xml', array(
                array( '#inner' => 'Three' ),
        )
 ), true);
-output_to_fd($doc, 1);
+print XML_Template_convert_doc_to_string($doc);
 ?>
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);