ledger/csv.cc
John Wiegley 4518ea9540 Value expression architecture is now rewritten, but the functionality of the
old system (for example, the meaning of 'a') has yet to be restored.  In the
new scheme, this will be done by definition a function outside of the value
expression logic, rather than the tight coupling between journal innards and
value expressions that occurred in 2.x.
2008-07-29 05:59:38 -04:00

118 lines
2.3 KiB
C++

#include "csv.h"
namespace ledger {
namespace {
inline void write_escaped_string(std::ostream& out, const string& xact)
{
out << "\"";
for (string::const_iterator i = xact.begin(); i != xact.end(); i++)
if (*i == '"') {
out << "\\";
out << "\"";
} else {
out << *i;
}
out << "\"";
}
}
void format_csv_transactions::operator()(transaction_t& xact)
{
if (! transaction_has_xdata(xact) ||
! (transaction_xdata_(xact).dflags & TRANSACTION_DISPLAYED)) {
{
format_t fmt("%D");
std::ostringstream str;
#if 0
fmt.format(str, details_t(xact));
#endif
write_escaped_string(out, str.str());
}
out << ',';
{
format_t fmt("%P");
std::ostringstream str;
#if 0
fmt.format(str, details_t(xact));
#endif
write_escaped_string(out, str.str());
}
out << ',';
{
format_t fmt("%A");
std::ostringstream str;
#if 0
fmt.format(str, details_t(xact));
#endif
write_escaped_string(out, str.str());
}
out << ',';
{
format_t fmt("%t");
std::ostringstream str;
#if 0
fmt.format(str, details_t(xact));
#endif
write_escaped_string(out, str.str());
}
out << ',';
{
format_t fmt("%T");
std::ostringstream str;
#if 0
fmt.format(str, details_t(xact));
#endif
write_escaped_string(out, str.str());
}
out << ',';
switch (xact.state) {
case transaction_t::CLEARED:
write_escaped_string(out, "*");
break;
case transaction_t::PENDING:
write_escaped_string(out, "!");
break;
default: {
transaction_t::state_t state;
if (xact.entry->get_state(&state))
switch (state) {
case transaction_t::CLEARED:
write_escaped_string(out, "*");
break;
case transaction_t::PENDING:
write_escaped_string(out, "!");
break;
default:
write_escaped_string(out, "");
break;
}
}
}
out << ',';
if (xact.entry->code)
write_escaped_string(out, *xact.entry->code);
out << ',';
{
format_t fmt("%N");
std::ostringstream str;
#if 0
fmt.format(str, details_t(xact));
#endif
write_escaped_string(out, str.str());
}
out << '\n';
transaction_xdata(xact).dflags |= TRANSACTION_DISPLAYED;
}
}
} // namespace ledger