diff options
author | John Wiegley <johnw@newartisans.com> | 2012-03-12 05:17:53 -0500 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2012-03-12 05:48:10 -0500 |
commit | fb2e80406fb61eb79a474fc683839c3536e55fb2 (patch) | |
tree | a6c59a38b3cc9f5a824c8340213de129ae666e0f /src/textual.cc | |
parent | ed71421c8a55a642969309f2a3f9baa49a37bb8b (diff) | |
download | fork-ledger-fb2e80406fb61eb79a474fc683839c3536e55fb2.tar.gz fork-ledger-fb2e80406fb61eb79a474fc683839c3536e55fb2.tar.bz2 fork-ledger-fb2e80406fb61eb79a474fc683839c3536e55fb2.zip |
Ignore all trailing whitespace in Ledger journals
Diffstat (limited to 'src/textual.cc')
-rw-r--r-- | src/textual.cc | 25 |
1 files changed, 12 insertions, 13 deletions
diff --git a/src/textual.cc b/src/textual.cc index a8cb844b..362bed4d 100644 --- a/src/textual.cc +++ b/src/textual.cc @@ -284,20 +284,23 @@ std::streamsize instance_t::read_line(char *& line) std::streamsize len = in.gcount(); if (len > 0) { - if (context.linenum == 0 && utf8::is_bom(context.linebuf)) - line = &context.linebuf[3]; - else - line = context.linebuf; - - if (line[len - 1] == '\r') // strip Windows CRLF down to LF - line[--len] = '\0'; - context.linenum++; context.curr_pos = context.line_beg_pos; context.curr_pos += len; - return len - 1; // LF is being silently dropped + if (context.linenum == 0 && utf8::is_bom(context.linebuf)) { + line = &context.linebuf[3]; + len -= 3; + } else { + line = context.linebuf; + } + + --len; + while (len > 0 && std::isspace(line[len - 1])) // strip trailing whitespace + line[--len] = '\0'; + + return len; } return 0; } @@ -542,7 +545,6 @@ void instance_t::automated_xact_directive(char * line) while (peek_whitespace_line()) { std::streamsize len = read_line(line); - char * p = skip_ws(line); if (! *p) break; @@ -1660,8 +1662,6 @@ bool instance_t::parse_posts(account_t * account, while (peek_whitespace_line()) { char * line; std::streamsize len = read_line(line); - assert(len > 0); - char * p = skip_ws(line); if (*p != ';') { if (post_t * post = parse_post(line, len, account, NULL, defer_expr)) { @@ -1754,7 +1754,6 @@ xact_t * instance_t::parse_xact(char * line, while (peek_whitespace_line()) { len = read_line(line); - char * p = skip_ws(line); if (! *p) break; |