(test): Added a test for the presence of <?xml... in the input stream;
if it is there, report an error based on whether XML support was actually compiled in or not.
This commit is contained in:
parent
5f33151837
commit
a1c6758265
2 changed files with 22 additions and 3 deletions
21
textual.cc
21
textual.cc
|
|
@ -304,6 +304,27 @@ static inline void parse_symbol(char *& p, std::string& symbol)
|
||||||
throw parse_error(path, linenum, "Failed to parse commodity");
|
throw parse_error(path, linenum, "Failed to parse commodity");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool textual_parser_t::test(std::istream& in) const
|
||||||
|
{
|
||||||
|
char buf[5];
|
||||||
|
|
||||||
|
assert(in.good());
|
||||||
|
in.read(buf, 5);
|
||||||
|
std::cerr << "buf (" << buf[0] << ")" << std::endl;
|
||||||
|
assert(in.good());
|
||||||
|
if (std::strncmp(buf, "<?xml", 5) == 0) {
|
||||||
|
#ifdef HAVE_XMLPARSE
|
||||||
|
throw parse_error(path, linenum, "Ledger file contains XML data, but no XML support present");
|
||||||
|
#else
|
||||||
|
throw parse_error(path, linenum, "Ledger file contains XML data, but format was not recognized");
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
in.seekg(0, std::ios::beg);
|
||||||
|
assert(in.good());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
unsigned int textual_parser_t::parse(std::istream& in,
|
unsigned int textual_parser_t::parse(std::istream& in,
|
||||||
journal_t * journal,
|
journal_t * journal,
|
||||||
account_t * master,
|
account_t * master,
|
||||||
|
|
|
||||||
|
|
@ -9,9 +9,7 @@ namespace ledger {
|
||||||
class textual_parser_t : public parser_t
|
class textual_parser_t : public parser_t
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual bool test(std::istream& in) const {
|
virtual bool test(std::istream& in) const;
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual unsigned int parse(std::istream& in,
|
virtual unsigned int parse(std::istream& in,
|
||||||
journal_t * journal,
|
journal_t * journal,
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue