mlisp/clib/csvparser.h

37 lines
772 B
C++

#pragma once
#include "../ml.h"
#include <math.h>
#include <string>
#include <vector>
#include <regex>
class CsvParser {
private:
char field_separator;
char line_separator;
char line_separator2;
char quote_character;
bool skip_header;
bool header_skiped;
public:
CsvParser(bool skip_hdr = false, char field_sep = ',', char quote_ch = '"', char line_sep = '\r',
char line_sep2 = '\n');
MlValue parseCSV(const std::string &csvSource);
private:
void add_row(const std::vector<MlValue> &columns, std::vector<MlValue> &rows);
static MlValue ivalualize(const std::string &value) ;
static bool is_string_int(const std::string &s, long &val) ;
static bool is_string_float(const std::string &s, double &val) ;
};