move constructing MlValues to clib from interpreter
This commit is contained in:
@@ -58,6 +58,33 @@ void CsvParser::parseCSV(const std::string &csvSource, std::vector< std::vector<
|
||||
addLine(line, lines);
|
||||
}
|
||||
|
||||
MlValue CsvParser::ivalualize(std::vector< std::vector<std::string> > &parsed_data) const {
|
||||
int rows = parsed_data.size();
|
||||
int cols = rows > 0 ? parsed_data[0].size() : 0;
|
||||
|
||||
std::vector<MlValue> result;
|
||||
|
||||
if (rows > 0 && cols > 0) {
|
||||
for (int r = 0; r < rows; r++) {
|
||||
std::vector<MlValue> row;
|
||||
for (int c = 0; c < cols; c++) {
|
||||
std::string value = parsed_data[r][c];
|
||||
if (is_string_int(value)) {
|
||||
row.push_back(MlValue(stoi(value)));
|
||||
}
|
||||
if (is_string_float(value)) {
|
||||
row.push_back(MlValue(std::stod(value)));
|
||||
} else {
|
||||
row.push_back(MlValue::string(value));
|
||||
}
|
||||
}
|
||||
result.push_back(row);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void CsvParser::addLine(const std::vector<std::string> &line, std::vector< std::vector<std::string> > &lines) {
|
||||
if (skip_header && !header_skiped) {
|
||||
header_skiped = true;
|
||||
@@ -66,3 +93,18 @@ void CsvParser::addLine(const std::vector<std::string> &line, std::vector< std::
|
||||
lines.push_back(line);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// std::regex int_underscored_regex("[0-9][0-9_]+[0-9]");
|
||||
std::regex int_regex("[0-9]+");
|
||||
std::regex double_regex("[0-9]+\\.[0-9]+");
|
||||
|
||||
// Is string representing int value
|
||||
bool CsvParser::is_string_int(const std::string &str) const {
|
||||
return std::regex_match(str, int_regex);
|
||||
}
|
||||
|
||||
// Is string representing float value
|
||||
bool CsvParser::is_string_float(const std::string &str) const {
|
||||
return std::regex_match(str, double_regex);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user