1 #include <msp/io/print.h>
2 #include <msp/strings/utils.h>
5 #include "textwriter.h"
12 TextWriter::TextWriter(Output &o):
15 float_format.showpoint().precision(7);
18 void TextWriter::set_float_precision(unsigned fp)
20 float_format.precision(fp/4-1);
23 void TextWriter::write(const Statement &st)
28 void TextWriter::write_(const Statement &st, unsigned level)
30 string indent(level, '\t');
32 out.write(format("%s%s", indent, st.keyword));
33 for(const Value &v: st.args)
36 if(v.get_signature()==StringType::signature)
37 out.write(format("\"%s\"", c_escape(v.get<StringType::Store>(), false)));
38 else if(v.get_signature()==BoolType::signature)
39 out.write(v.get<BoolType::Store>() ? "true" : "false");
40 else if(v.get_signature()==IntType::signature)
41 out.write(lexical_cast<string>(v.get<IntType::Store>()));
42 else if(v.get_signature()==FloatType::signature)
43 out.write(lexical_cast<string>(v.get<FloatType::Store>(), float_format));
44 else if(v.get_signature()==SymbolType::signature)
46 string name = v.get<SymbolType::Store>().name;
55 out.write(format("\n%s{\n", indent));
56 for(const Statement &s: st.sub)
58 out.write(format("%s}", indent));
63 } // namespace DataFile