summaryrefslogtreecommitdiff
path: root/amount.cc
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2007-04-17 02:56:53 +0000
committerJohn Wiegley <johnw@newartisans.com>2008-04-13 03:35:35 -0400
commite43f54f24936a0fd93ae9dba8a163982ede0e1ab (patch)
tree49524c2bccb740f362c25eebce6c7808e8a74222 /amount.cc
parente7f9486f6e524947a29b8e7d20bc834a240a3b23 (diff)
downloadfork-ledger-e43f54f24936a0fd93ae9dba8a163982ede0e1ab.tar.gz
fork-ledger-e43f54f24936a0fd93ae9dba8a163982ede0e1ab.tar.bz2
fork-ledger-e43f54f24936a0fd93ae9dba8a163982ede0e1ab.zip
Started adding commodity tests
Diffstat (limited to 'amount.cc')
-rw-r--r--amount.cc9
1 files changed, 5 insertions, 4 deletions
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);
}