summaryrefslogtreecommitdiff
path: root/src/csv.h
diff options
context:
space:
mode:
authorKai Wohlfahrt <kai.wohlfahrt@gmail.com>2020-06-10 16:48:52 +0100
committerMartin Michlmayr <tbm@cyrius.com>2021-01-31 09:59:02 +0800
commitff1d1d9e5c93fa84a3abcb5bb5e21013ee8f77d9 (patch)
tree6ce78371b8d99e33352a8713c6c7865450c76129 /src/csv.h
parent0e44585153b82c9e6730e49af3fa27aeb5b82b5f (diff)
downloadfork-ledger-ff1d1d9e5c93fa84a3abcb5bb5e21013ee8f77d9.tar.gz
fork-ledger-ff1d1d9e5c93fa84a3abcb5bb5e21013ee8f77d9.tar.bz2
fork-ledger-ff1d1d9e5c93fa84a3abcb5bb5e21013ee8f77d9.zip
Replace if/else ladder in convert with loop
Diffstat (limited to 'src/csv.h')
-rw-r--r--src/csv.h33
1 files changed, 13 insertions, 20 deletions
diff --git a/src/csv.h b/src/csv.h
index 9747a775..d7083211 100644
--- a/src/csv.h
+++ b/src/csv.h
@@ -71,31 +71,24 @@ class csv_reader
FIELD_UNKNOWN
};
- mask_t date_mask;
- mask_t date_aux_mask;
- mask_t code_mask;
- mask_t payee_mask;
- mask_t credit_mask;
- mask_t debit_mask;
- mask_t cost_mask;
- mask_t total_mask;
- mask_t note_mask;
-
- std::vector<int> index;
+ std::array<std::pair<mask_t, headers_t>, 10> masks;
+
+ std::vector<headers_t> index;
std::vector<string> names;
public:
csv_reader(parse_context_t& _context)
: context(_context),
- date_mask("date"),
- date_aux_mask("posted( ?date)?"),
- code_mask("code"),
- payee_mask("(payee|desc(ription)?|title)"),
- credit_mask("credit|amount"),
- debit_mask("debit"),
- cost_mask("cost"),
- total_mask("total"),
- note_mask("note") {
+ masks{ std::make_pair(mask_t("date"), FIELD_DATE),
+ std::make_pair(mask_t("posted( ?date)?"), FIELD_DATE_AUX),
+ std::make_pair(mask_t("code"), FIELD_CODE),
+ std::make_pair(mask_t("(payee|desc(ription)?|title)"), FIELD_PAYEE),
+ std::make_pair(mask_t("credit|amount"), FIELD_CREDIT),
+ std::make_pair(mask_t("debit"), FIELD_DEBIT),
+ std::make_pair(mask_t("cost"), FIELD_COST),
+ std::make_pair(mask_t("total"), FIELD_TOTAL),
+ std::make_pair(mask_t("note"), FIELD_NOTE),
+ std::make_pair(mask_t(""), FIELD_UNKNOWN) } {
read_index(*context.stream.get());
TRACE_CTOR(csv_reader, "parse_context_t&");
}