From b9e2078e5a007ec8c26605f2ab76dd14c20a1e9f Mon Sep 17 00:00:00 2001 From: John Denker Date: Mon, 18 Oct 2021 12:28:15 -0700 Subject: relocate count_header code to more appropriate file --- parse_csv.c | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) (limited to 'parse_csv.c') diff --git a/parse_csv.c b/parse_csv.c index 12e98f3..423fe77 100644 --- a/parse_csv.c +++ b/parse_csv.c @@ -168,17 +168,42 @@ vector > readCSV(istream &in) { return table; } +// Scan the data array, +// looking for records that look like headers +// (as opposed to numerical data). +template +int count_header(vector > const aoa){ + int NR = aoa.size(); + int hh = 0; + for (; hh < NR; hh++) { + if (aoa[hh].size() == 0) continue; + string word = aoa[hh][0]; + size_t where; + where = word.find_first_not_of(" "); + if (where == string::npos) continue; + word = word.substr(where); + try { + stod(word, &where); // don't care about return value + } + catch (exception& ee) { + continue; + } + word = word.substr(where); + where = word.find_first_not_of(" "); + if (where == string::npos) break; + } + return hh; +} + // Explicit instantiation for the version. // If you want some other version, you'll have to instantiate it. template vector readCSVRow(istream& input); template vector >readCSV(istream &in); -// Apparently it's not necessary to mention get_q() here, -// but probably more portable to do it anyway: -////template int get_q(qstring const&); +template int count_header(vector > const aoa); #if 1 // Explicit instantiation for the version. template vector readCSVRow(istream& input); template vector >readCSV(istream &in); -/////template int get_q(string const&); +template int count_header(vector > const aoa); #endif -- cgit v1.2.3