summaryrefslogtreecommitdiff
path: root/src/csv.h
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2010-03-07 22:53:03 -0500
committerJohn Wiegley <johnw@newartisans.com>2010-03-08 01:11:55 -0500
commite070cdfc8ddcf9d6a25b593502f1c5ade56c849c (patch)
tree0ed450b5a7e326501dbda8119a90684d6d95df3b /src/csv.h
parent89992ad4b8b6e7d9ab7c051f50abe6fae7277f73 (diff)
downloadfork-ledger-e070cdfc8ddcf9d6a25b593502f1c5ade56c849c.tar.gz
fork-ledger-e070cdfc8ddcf9d6a25b593502f1c5ade56c849c.tar.bz2
fork-ledger-e070cdfc8ddcf9d6a25b593502f1c5ade56c849c.zip
The CSV reader now auto-correlates fields by regex
Diffstat (limited to 'src/csv.h')
-rw-r--r--src/csv.h45
1 files changed, 43 insertions, 2 deletions
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<int> index;
+ std::vector<string> names;
+ std::vector<string> fields;
+
+ typedef std::map<string, string> 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);
};