]> git.tdb.fi Git - libs/datafile.git/blobdiff - source/textwriter.cpp
Style update: add spaces around assignments
[libs/datafile.git] / source / textwriter.cpp
index 68111c0d3038c9b6b4b0f1f0a70df6b436d0c167..2768462297e6fed397e31b8a7ae58e96b3110113 100644 (file)
@@ -5,6 +5,8 @@ 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"
 
@@ -13,7 +15,7 @@ using namespace std;
 namespace Msp {
 namespace DataFile {
 
-TextWriter::TextWriter(ostream &o):
+TextWriter::TextWriter(IO::Base &o):
        WriterMode(o)
 { }
 
@@ -26,25 +28,25 @@ void TextWriter::write_(const Statement &st, unsigned level)
 {
        string indent(level, '\t');
 
-       out<<indent<<st.keyword;
-       for(ValueArray::const_iterator i=st.args.begin(); i!=st.args.end(); ++i)
+       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<<'\"'<<i->get_raw()<<'\"';
+                       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";
-               for(list<Statement>::const_iterator i=st.sub.begin(); i!=st.sub.end(); ++i)
+               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