3 This file is part of libmspdatafile
4 Copyright © 2006 Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
8 #include <msp/io/print.h>
9 #include <msp/strings/utils.h>
10 #include "statement.h"
11 #include "textwriter.h"
18 TextWriter::TextWriter(IO::Base &o):
22 void TextWriter::write(const Statement &st)
27 void TextWriter::write_(const Statement &st, unsigned level)
29 string indent(level, '\t');
31 IO::print(out, "%s%s", indent, st.keyword);
32 for(ValueArray::const_iterator i=st.args.begin(); i!=st.args.end(); ++i)
35 if(i->get_type()==STRING)
36 IO::print(out, "\"%s\"", c_escape(i->get_raw(), false));
37 else if(i->get_type()==BOOLEAN)
38 out.write(i->get<bool>() ? "true" : "false");
40 out.write(i->get_raw());
44 IO::print(out, "\n%s{\n", indent);
45 for(list<Statement>::const_iterator i=st.sub.begin(); i!=st.sub.end(); ++i)
47 IO::print(out, "%s}", indent);
52 } // namespace DataFile