From ed0deb95c22e52c20b29a243b7c3c4db363fc67c Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Thu, 17 Jul 2008 18:31:36 -0400 Subject: Strip \r from all lines read. --- textual.cc | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) (limited to 'textual.cc') diff --git a/textual.cc b/textual.cc index 081e411c..61cf37f8 100644 --- a/textual.cc +++ b/textual.cc @@ -335,12 +335,17 @@ bool parse_transactions(std::istream& in, in.getline(line, MAX_LINE); if (in.eof()) break; - beg_pos += std::strlen(line) + 1; + + int len = std::strlen(line); + if (line[len - 1] == '\r') + line[--len] == '\0'; + + beg_pos += len + 1; linenum++; - if (line[0] == ' ' || line[0] == '\t' || line[0] == '\r') { + if (line[0] == ' ' || line[0] == '\t') { char * p = skip_ws(line); - if (! *p || *p == '\r') + if (! *p) break; } if (transaction_t * xact = parse_transaction(line, account)) { @@ -426,12 +431,17 @@ entry_t * parse_entry(std::istream& in, char * line, account_t * master, in.getline(line, MAX_LINE); if (in.eof() && line[0] == '\0') break; - end_pos = beg_pos + std::strlen(line) + 1; + + int len = std::strlen(line); + if (line[len - 1] == '\r') + line[--len] == '\0'; + + end_pos = beg_pos + len + 1; linenum++; - if (line[0] == ' ' || line[0] == '\t' || line[0] == '\r') { + if (line[0] == ' ' || line[0] == '\t') { char * p = skip_ws(line); - if (! *p || *p == '\r') + if (! *p) break; } @@ -608,18 +618,22 @@ unsigned int textual_parser_t::parse(std::istream& in, in.getline(line, MAX_LINE); if (in.eof()) break; - end_pos = beg_pos + std::strlen(line) + 1; + + int len = std::strlen(line); + if (line[len - 1] == '\r') + line[--len] == '\0'; + + end_pos = beg_pos + len + 1; linenum++; switch (line[0]) { case '\0': - case '\r': break; case ' ': case '\t': { char * p = skip_ws(line); - if (*p && *p != '\r') + if (*p) throw new parse_error("Line begins with whitespace"); break; } -- cgit v1.2.3