(parse): Accept CX as well as C*. Also, general improvements to Bank

type parser.
This commit is contained in:
John Wiegley 2005-06-20 00:31:48 +00:00
parent 6d14952e1e
commit fdf73faff7

27
qif.cc
View file

@ -113,7 +113,8 @@ unsigned int qif_parser_t::parse(std::istream& in,
}
case 'C':
if (in.peek() == '*') {
c = in.peek();
if (c == '*' || c == 'X') {
in.get(c);
entry->state = entry_t::CLEARED;
}
@ -131,13 +132,9 @@ unsigned int qif_parser_t::parse(std::istream& in,
case 'L':
case 'S':
case 'E': {
char b = c;
int len;
c = in.peek();
if (! std::isspace(c) && c != '\n') {
get_line(in);
switch (b) {
switch (c) {
case 'P':
entry->payee = line;
break;
@ -146,20 +143,20 @@ unsigned int qif_parser_t::parse(std::istream& in,
xact = new transaction_t(NULL);
entry->add_transaction(xact);
// fall through...
case 'L':
len = std::strlen(line);
case 'L': {
int len = std::strlen(line);
if (line[len - 1] == ']')
line[len - 1] = '\0';
xact->account = journal->find_account(line[0] == '[' ?
line + 1 : line);
break;
}
case 'M':
case 'E':
xact->note = line;
break;
}
}
break;
}
@ -168,14 +165,19 @@ unsigned int qif_parser_t::parse(std::istream& in,
get_line(in);
break;
case '^':
case '^': {
account_t * other;
if (xact->account == master) {
if (! misc)
misc = journal->find_account("Miscellaneous");
transaction_t * nxact = new transaction_t(misc);
other = misc;
} else {
other = master;
}
transaction_t * nxact = new transaction_t(other);
entry->add_transaction(nxact);
nxact->amount.negate();
}
if (journal->add_entry(entry.get())) {
entry.release();
@ -188,6 +190,7 @@ unsigned int qif_parser_t::parse(std::istream& in,
break;
}
}
}
return count;
}