Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/just_gtfs.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOlga Khlopkova <o.khlopkova@corp.mail.ru>2020-04-30 16:04:08 +0300
committerOlga Khlopkova <o.khlopkova@corp.mail.ru>2020-04-30 16:04:08 +0300
commit7f6f960ed74dbb71c26ea9cbaac06fda7e3f51aa (patch)
tree06829d7baee059b3ad33dd2f334be2f46e1c2677
parentb0bc8951469d6d4bd9d0a416b77765b2ae0ad80c (diff)
Fix for csv with different count of fields in header and row
-rw-r--r--include/just_gtfs/just_gtfs.h18
1 files changed, 6 insertions, 12 deletions
diff --git a/include/just_gtfs/just_gtfs.h b/include/just_gtfs/just_gtfs.h
index 07c6cc6..cd8e5c6 100644
--- a/include/just_gtfs/just_gtfs.h
+++ b/include/just_gtfs/just_gtfs.h
@@ -159,27 +159,21 @@ inline Result CsvParser::read_header(const std::string & csv_filename)
inline Result CsvParser::read_row(std::map<std::string, std::string> & obj)
{
+ obj = {};
std::string row;
if (!getline(csv_stream, row))
- {
- obj = {};
return {ResultCode::END_OF_FILE, {}};
- }
if (row == "\r")
- {
- obj = {};
return {ResultCode::OK, {}};
- }
- std::vector<std::string> fields_values = split_record(row);
+ const std::vector<std::string> fields_values = split_record(row);
- // Different count of fields in row and in the header of csv.
- // Typical approach to skip not required fields.
- if (fields_values.size() != field_sequence.size())
- obj = {};
+ // Different count of fields in the row and in the header of csv.
+ // Typical approach is to skip not required fields.
+ const size_t fields_count = std::min(field_sequence.size(), fields_values.size());
- for (size_t i = 0; i < field_sequence.size(); ++i)
+ for (size_t i = 0; i < fields_count; ++i)
obj[field_sequence[i]] = fields_values[i];
return {ResultCode::OK, {}};