From e070cdfc8ddcf9d6a25b593502f1c5ade56c849c Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Sun, 7 Mar 2010 22:53:03 -0500 Subject: The CSV reader now auto-correlates fields by regex --- src/csv.h | 45 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) (limited to 'src/csv.h') diff --git a/src/csv.h b/src/csv.h index 7029d482..5ff8b59e 100644 --- a/src/csv.h +++ b/src/csv.h @@ -56,10 +56,51 @@ class csv_reader std::istream& in; + enum headers_t { + FIELD_DATE = 0, + FIELD_DATE_EFF, + FIELD_CODE, + FIELD_PAYEE, + FIELD_AMOUNT, + FIELD_COST, + FIELD_TOTAL, + FIELD_NOTE, + + FIELD_UNKNOWN + }; + + mask_t date_mask; + mask_t date_eff_mask; + mask_t code_mask; + mask_t payee_mask; + mask_t amount_mask; + mask_t cost_mask; + mask_t total_mask; + mask_t note_mask; + + std::vector index; + std::vector names; + std::vector fields; + + typedef std::map string_map; + public: - csv_reader(std::istream& _in) : in(_in) {} + csv_reader(std::istream& _in) + : in(_in), + date_mask("date"), + date_eff_mask("posted( ?date)?"), + code_mask("code"), + payee_mask("(payee|desc(ription)?|title)"), + amount_mask("amount"), + cost_mask("cost"), + total_mask("total"), + note_mask("note") { + read_index(in); + } - string read_field(); + string read_field(std::istream& in); + char * next_line(std::istream& in); + void read_index(std::istream& in); xact_t * read_xact(journal_t& journal, account_t * bucket); }; -- cgit v1.2.3