]> git.tdb.fi Git - libs/datafile.git/blobdiff - source/textwriter.cpp
Use libmspio instead of C++ iostreams
[libs/datafile.git] / source / textwriter.cpp
index def744c33b06ff945c4cfccbe28025bb43402872..890c4172162ea17631d8bc69fad7be8ce3a28788 100644 (file)
@@ -5,6 +5,7 @@ Copyright © 2006  Mikko Rasa, Mikkosoft Productions
 Distributed under the LGPL
 */
 
+#include <msp/io/print.h>
 #include <msp/strings/utils.h>
 #include "statement.h"
 #include "textwriter.h"
@@ -14,7 +15,7 @@ using namespace std;
 namespace Msp {
 namespace DataFile {
 
-TextWriter::TextWriter(ostream &o):
+TextWriter::TextWriter(IO::Base &o):
        WriterMode(o)
 { }
 
@@ -27,25 +28,25 @@ void TextWriter::write_(const Statement &st, unsigned level)
 {
        string indent(level, '\t');
 
-       out<<indent<<st.keyword;
+       IO::print(out, "%s%s", indent, st.keyword);
        for(ValueArray::const_iterator i=st.args.begin(); i!=st.args.end(); ++i)
        {
-               out<<' ';
+               out.put(' ');
                if(i->get_type()==STRING)
-                       out<<'\"'<<c_escape(i->get_raw(), false)<<'\"';
+                       IO::print(out, "\"%s\"", c_escape(i->get_raw(), false));
                else if(i->get_type()==BOOLEAN)
-                       out<<(i->get<bool>() ? "true" : "false");
+                       out.write(i->get<bool>() ? "true" : "false");
                else
-                       out<<i->get_raw();
+                       out.write(i->get_raw());
        }
        if(!st.sub.empty())
        {
-               out<<'\n'<<indent<<"{\n";
+               IO::print(out, "\n%s{\n", indent);
                for(list<Statement>::const_iterator i=st.sub.begin(); i!=st.sub.end(); ++i)
                        write_(*i, level+1);
-               out<<indent<<'}';
+               IO::print(out, "%s}", indent);
        }
-       out<<";\n";
+       out.write(";\n", 2);
 }
 
 } // namespace DataFile