summaryrefslogtreecommitdiff
path: root/src/commodity.cc
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2010-06-09 06:45:07 -0400
committerJohn Wiegley <johnw@newartisans.com>2010-06-09 06:45:07 -0400
commit8637dd6ccf7afc71d911cd66c4a55a1308596dbb (patch)
tree64a6f4bdadfb59fe25eec507b6b9024653087ee0 /src/commodity.cc
parentda2f415f148b69898d71405235eaa8b36aa21b3b (diff)
downloadfork-ledger-8637dd6ccf7afc71d911cd66c4a55a1308596dbb.tar.gz
fork-ledger-8637dd6ccf7afc71d911cd66c4a55a1308596dbb.tar.bz2
fork-ledger-8637dd6ccf7afc71d911cd66c4a55a1308596dbb.zip
New display flag AMOUNT_PRINT_ELIDE_COMMODITY_QUOTES
This is used by reports like register and balance so that separated commodities without spaces in them needed be surrounded by quotes. It will still occur in most other places. Fixes #200 / F82CF11F-BFD9-4512-A562-202B04B68051
Diffstat (limited to 'src/commodity.cc')
-rw-r--r--src/commodity.cc11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/commodity.cc b/src/commodity.cc
index 9a757395..44d14c56 100644
--- a/src/commodity.cc
+++ b/src/commodity.cc
@@ -642,6 +642,17 @@ void commodity_t::parse_symbol(char *& p, string& symbol)
throw_(amount_error, _("Failed to parse commodity"));
}
+void commodity_t::print(std::ostream& out, bool elide_quotes) const
+{
+ string sym = symbol();
+ if (elide_quotes && has_flags(COMMODITY_STYLE_SEPARATED) &&
+ ! sym.empty() && sym[0] == '"' && ! std::strchr(sym.c_str(), ' ')) {
+ DEBUG("foo", "contracting " << sym << " to " << string(sym, 1, sym.length() - 2));
+ out << string(sym, 1, sym.length() - 2);
+ } else
+ out << sym;
+}
+
bool commodity_t::valid() const
{
if (symbol().empty() && this != pool().null_commodity) {