From a10f3f02e711b67e754e5a9430a09144e3339133 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Thu, 23 Jun 2005 00:07:50 +0000 Subject: (parse): Allow "-$100.00" as the equivalent of "$-100.00". --- amount.cc | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/amount.cc b/amount.cc index 16d9cbf4..decebe38 100644 --- a/amount.cc +++ b/amount.cc @@ -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(); } -- cgit v1.2.3