-/* $Id$
-
-This file is part of libmspdatafile
-Copyright © 2007-2008, 2010 Mikko Rasa, Mikkosoft Productions
-Distributed under the LGPL
-*/
-
#include <msp/io/print.h>
#include <msp/strings/utils.h>
#include "statement.h"
namespace DataFile {
TextWriter::TextWriter(IO::Base &o):
- WriterMode(o)
+ WriterMode(o),
+ float_format("%#.7g")
{ }
+void TextWriter::set_float_precision(unsigned fp)
+{
+ float_format = format("%%#.%dg", fp/4-1);
+}
+
void TextWriter::write(const Statement &st)
{
write_(st, 0);
else if(i->get_signature()==IntType::signature)
out.write(lexical_cast(i->get<IntType::Store>()));
else if(i->get_signature()==FloatType::signature)
- out.write(format("%15g", (i->get<FloatType::Store>())));
+ out.write(format(float_format, i->get<FloatType::Store>()));
else if(i->get_signature()==SymbolType::signature)
- out.write(i->get<SymbolType::Store>().name);
+ {
+ string name = i->get<SymbolType::Store>().name;
+ if(isdigit(name[0]))
+ out.write("\\"+name);
+ else
+ out.write(name);
+ }
}
if(!st.sub.empty())
{