diff options
author | John Wiegley <johnw@newartisans.com> | 2005-06-23 00:07:50 +0000 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2008-04-13 02:41:12 -0400 |
commit | a10f3f02e711b67e754e5a9430a09144e3339133 (patch) | |
tree | e4fa067e441a8b6b347e33acf56833a8e0a1f87c | |
parent | a2015ee5103516b6881a2976a3150aa0f357f347 (diff) | |
download | fork-ledger-a10f3f02e711b67e754e5a9430a09144e3339133.tar.gz fork-ledger-a10f3f02e711b67e754e5a9430a09144e3339133.tar.bz2 fork-ledger-a10f3f02e711b67e754e5a9430a09144e3339133.zip |
(parse): Allow "-$100.00" as the equivalent of "$-100.00".
-rw-r--r-- | amount.cc | 14 |
1 files changed, 12 insertions, 2 deletions
@@ -858,10 +858,17 @@ void amount_t::parse(std::istream& in, unsigned short flags) std::string symbol; std::string quant; - unsigned int comm_flags = COMMODITY_STYLE_DEFAULTS;; + unsigned int comm_flags = COMMODITY_STYLE_DEFAULTS; + bool negative = false; char c = peek_next_nonws(in); - if (std::isdigit(c) || c == '.' || c == '-') { + if (c == '-') { + negative = true; + in.get(c); + c = peek_next_nonws(in); + } + + if (std::isdigit(c) || c == '.') { parse_quantity(in, quant); char n; @@ -955,6 +962,9 @@ void amount_t::parse(std::istream& in, unsigned short flags) mpz_set_str(MPZ(quantity), quant.c_str(), 10); } + if (negative) + negate(); + if (! (flags & AMOUNT_PARSE_NO_REDUCE)) reduce(); } |