summaryrefslogtreecommitdiff
path: root/src/csv.cc
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.cc
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.cc')
-rw-r--r--src/csv.cc27
1 files changed, 6 insertions, 21 deletions
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;
+ }
+ }
}
}