summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2009-01-22 21:15:05 -0400
committerJohn Wiegley <johnw@newartisans.com>2009-01-22 21:15:05 -0400
commitd9e97cfede4afcda55eaa8defaaa63c0c18065b1 (patch)
tree64ff68ce8a473c4af114eccb4c504df936f42b30 /src
parent7b76ea5cbcc7a9e5207f7754cfee558037870a96 (diff)
downloadledger-d9e97cfede4afcda55eaa8defaaa63c0c18065b1.tar.gz
ledger-d9e97cfede4afcda55eaa8defaaa63c0c18065b1.tar.bz2
ledger-d9e97cfede4afcda55eaa8defaaa63c0c18065b1.zip
When parsing commodities, if there is no symbol or annotations, reset the
stream pointer in order to give more accurate error reporting.
Diffstat (limited to 'src')
-rw-r--r--src/commodity.cc11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/commodity.cc b/src/commodity.cc
index d441012b..02aa5e81 100644
--- a/src/commodity.cc
+++ b/src/commodity.cc
@@ -508,6 +508,8 @@ void commodity_t::parse_symbol(std::istream& in, string& symbol)
/* f0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
};
+ istream_pos_type pos = in.tellg();
+
char buf[256];
char c = peek_next_nonws(in);
if (c == '"') {
@@ -521,6 +523,11 @@ void commodity_t::parse_symbol(std::istream& in, string& symbol)
READ_INTO(in, buf, 255, c, ! invalid_chars[static_cast<unsigned char>(c)]);
}
symbol = buf;
+
+ if (symbol.length() == 0) {
+ in.clear();
+ in.seekg(pos, std::ios::beg);
+ }
}
void commodity_t::parse_symbol(char *& p, string& symbol)
@@ -567,6 +574,8 @@ bool commodity_t::valid() const
void annotation_t::parse(std::istream& in)
{
do {
+ istream_pos_type pos = in.tellg();
+
char buf[256];
char c = peek_next_nonws(in);
if (c == '{') {
@@ -621,6 +630,8 @@ void annotation_t::parse(std::istream& in)
tag = buf;
}
else {
+ in.clear();
+ in.seekg(pos, std::ios::beg);
break;
}
} while (true);