small rectorings

This commit is contained in:
2022-01-16 20:40:09 +01:00
parent 10bd95da65
commit 796f6a5785
6 changed files with 155 additions and 149 deletions

View File

@@ -26,30 +26,31 @@ MlValue CsvParser::parseCSV(const std::string &csvSource) {
line.reserve(32); // TODO introduce constant here
std::string::const_iterator aChar = csvSource.begin();
while (aChar != csvSource.end()) {
std::string::const_iterator aEnd = csvSource.end();
while (aChar != aEnd) {
if (*aChar == quote_character) {
newLine = false;
inQuote = !inQuote;
} else if (*aChar == field_separator) {
newLine = false;
if (inQuote == true) {
if (inQuote) {
field += *aChar;
} else {
line.push_back(ivalualize(field));
field.clear();
}
} else if (*aChar == line_separator || *aChar == line_separator2) {
if (inQuote == true) {
if (inQuote) {
field += *aChar;
} else {
if (newLine == false) {
if (!newLine) {
line.push_back(ivalualize(field));
add_line(line, parsed_data);
field.clear();
line.clear();
linesRead++;
if (linesRead == 16) {
int linesEstimation = csvSource.size() / (std::distance(csvSource.begin(), aChar) / linesRead);
size_t linesEstimation = csvSource.size() / (std::distance(csvSource.begin(), aChar) / linesRead);
if (linesEstimation > parsed_data.capacity())
parsed_data.reserve(linesEstimation);
}
@@ -64,7 +65,7 @@ MlValue CsvParser::parseCSV(const std::string &csvSource) {
aChar++;
}
if (field.size())
if (!field.empty())
line.push_back(ivalualize(field));
add_line(line, parsed_data);
@@ -77,12 +78,12 @@ void CsvParser::add_line(const std::vector<MlValue> &line, std::vector<MlValue>
if (skip_header && !header_skiped) {
header_skiped = true;
} else {
if (line.size())
lines.push_back(line);
if (!line.empty())
lines.emplace_back(line);
}
}
MlValue CsvParser::ivalualize(const std::string &value) const {
MlValue CsvParser::ivalualize(const std::string &value) {
long int_val;
double float_val;
if (value.empty() || ((!isdigit(value[0])) && (value[0] != '-') && (value[0] != '+'))) {
@@ -97,7 +98,7 @@ MlValue CsvParser::ivalualize(const std::string &value) const {
}
// Is string representing int value
bool CsvParser::is_string_int(const std::string &s, long &val) const {
bool CsvParser::is_string_int(const std::string &s, long &val) {
char *end_ptr;
errno = 0;
// if(s.empty() || ((!isdigit(s[0])) && (s[0] != '-') && (s[0] != '+'))) return false;
@@ -110,7 +111,7 @@ bool CsvParser::is_string_int(const std::string &s, long &val) const {
}
// Is string representing float value
bool CsvParser::is_string_float(const std::string &s, double &val) const {
bool CsvParser::is_string_float(const std::string &s, double &val) {
char *end_ptr;
errno = 0;
// if(s.empty() || ((!isdigit(s[0])) && (s[0] != '-') && (s[0] != '+'))) return false;