When parsing commodities, if there is no symbol or annotations, reset the

stream pointer in order to give more accurate error reporting.
This commit is contained in:
John Wiegley 2009-01-22 21:15:05 -04:00
parent 7b76ea5cbc
commit d9e97cfede

View file

@ -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);