From ff1d1d9e5c93fa84a3abcb5bb5e21013ee8f77d9 Mon Sep 17 00:00:00 2001 From: Kai Wohlfahrt Date: Wed, 10 Jun 2020 16:48:52 +0100 Subject: Replace if/else ladder in convert with loop --- src/csv.cc | 27 ++++++--------------------- 1 file changed, 6 insertions(+), 21 deletions(-) (limited to 'src/csv.cc') diff --git a/src/csv.cc b/src/csv.cc index 4ee7ff60..632ec8d6 100644 --- a/src/csv.cc +++ b/src/csv.cc @@ -107,28 +107,13 @@ void csv_reader::read_index(std::istream& in) string field = read_field(instr); names.push_back(field); - if (date_mask.match(field)) - index.push_back(FIELD_DATE); - else if (date_aux_mask.match(field)) - index.push_back(FIELD_DATE_AUX); - else if (code_mask.match(field)) - index.push_back(FIELD_CODE); - else if (payee_mask.match(field)) - index.push_back(FIELD_PAYEE); - else if (credit_mask.match(field)) - index.push_back(FIELD_CREDIT); - else if (debit_mask.match(field)) - index.push_back(FIELD_DEBIT); - else if (cost_mask.match(field)) - index.push_back(FIELD_COST); - else if (total_mask.match(field)) - index.push_back(FIELD_TOTAL); - else if (note_mask.match(field)) - index.push_back(FIELD_NOTE); - else - index.push_back(FIELD_UNKNOWN); - DEBUG("csv.parse", "Header field: " << field); + for (auto& mask : masks) { + if (mask.first.match(field)) { + index.push_back(mask.second); + break; + } + } } } -- cgit v1.2.3