From e43f54f24936a0fd93ae9dba8a163982ede0e1ab Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Tue, 17 Apr 2007 02:56:53 +0000 Subject: Started adding commodity tests --- amount.cc | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'amount.cc') diff --git a/amount.cc b/amount.cc index ee654328..bcf29d06 100644 --- a/amount.cc +++ b/amount.cc @@ -1123,7 +1123,7 @@ static void parse_commodity(std::istream& in, std::string& symbol) symbol = buf; } -void parse_annotations(std::istream& in, amount_t& price, +bool parse_annotations(std::istream& in, amount_t& price, datetime_t& date, std::string& tag) { do { @@ -1200,6 +1200,7 @@ void amount_t::parse(std::istream& in, unsigned char flags) std::string quant; amount_t tprice; datetime_t tdate; + bool had_date = false; std::string tag; unsigned int comm_flags = COMMODITY_STYLE_DEFAULTS; bool negative = false; @@ -1225,7 +1226,7 @@ void amount_t::parse(std::istream& in, unsigned char flags) comm_flags |= COMMODITY_STYLE_SUFFIXED; if (! in.eof() && ((n = in.peek()) != '\n')) - parse_annotations(in, tprice, tdate, tag); + had_date = parse_annotations(in, tprice, tdate, tag); } } else { parse_commodity(in, symbol); @@ -1237,7 +1238,7 @@ void amount_t::parse(std::istream& in, unsigned char flags) parse_quantity(in, quant); if (! quant.empty() && ! in.eof() && ((n = in.peek()) != '\n')) - parse_annotations(in, tprice, tdate, tag); + had_date = parse_annotations(in, tprice, tdate, tag); } } @@ -1261,7 +1262,7 @@ void amount_t::parse(std::istream& in, unsigned char flags) } assert(commodity_); - if (! tprice.realzero() || tdate || ! tag.empty()) + if (! tprice.realzero() || had_date || ! tag.empty()) commodity_ = annotated_commodity_t::find_or_create(*commodity_, tprice, tdate, tag); } -- cgit v1.2.3