aboutsummaryrefslogtreecommitdiff
path: root/parse_csv.h
diff options
context:
space:
mode:
authorJohn Denker <jsd@av8n.com>2021-10-17 10:10:18 -0700
committerJohn Denker <jsd@av8n.com>2021-10-17 11:09:24 -0700
commit74ddd0381aa1b1a90eb0d5300fa576cb2348eeac (patch)
tree72a9dded6f800467d52e479eb37574e6de5f2e6c /parse_csv.h
parent634d365a03cb0581a062cd3cf4db9ae69f1cde26 (diff)
basically functional, but still a work in progress
Diffstat (limited to 'parse_csv.h')
-rw-r--r--parse_csv.h34
1 files changed, 34 insertions, 0 deletions
diff --git a/parse_csv.h b/parse_csv.h
new file mode 100644
index 0000000..362c478
--- /dev/null
+++ b/parse_csv.h
@@ -0,0 +1,34 @@
+#ifndef PARSE_CSV__H
+#define PARSE_CSV__H
+#include <vector>
+
+struct qstring : public std::string {
+ int q; // was explicitly quoted
+// Constructors:
+ qstring(): q(0) {}
+ qstring(int const _q): q(_q) {}
+ qstring(std::string const &s): std::string(s), q(0) {}
+ qstring(std::string const &s, int const _q): std::string(s), q(_q) {}
+};
+
+// Helper functions, not class member functions:
+// Simple case, do nothing:
+template<class T> inline void set_q(T& target, int const val) {}
+template<class T> inline int get_q(T const& target) {return 0;}
+
+// Specialization: Fancy case, actually act on q:
+template<> inline void set_q(qstring& target, int const val) {
+ target.q = val;
+}
+
+template<> inline int get_q(qstring const& target){
+ return target.q;
+}
+
+template <class datum = qstring>
+std::vector<datum> readCSVRow(std::istream& input);
+
+template <class datum = qstring>
+std::vector<std::vector<datum> > readCSV(std::istream &in);
+
+#endif