From 8772755a0baeb2d4498f3d3d1c5a6a2bbc005892 Mon Sep 17 00:00:00 2001 From: Matt Williamson <87771120+mattw-nws@users.noreply.github.com> Date: Wed, 22 Mar 2023 18:17:06 +0000 Subject: [PATCH 1/2] Handle windows CSV files on Linux --- include/utilities/CSV_Reader.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/include/utilities/CSV_Reader.h b/include/utilities/CSV_Reader.h index c2e845bf09..341181bcb6 100644 --- a/include/utilities/CSV_Reader.h +++ b/include/utilities/CSV_Reader.h @@ -46,6 +46,11 @@ inline std::vector > CSVReader::getData() // Iterate through each line and split the content using delimeter while (getline(file, line)) { + // Consider more robust solution like https://stackoverflow.com/a/6089413/489116 + if ( line.size() && line[line.size()-1] == '\r' ) { + line = line.substr( 0, line.size() - 1 ); + } + std::vector vec; /// \todo Look into replacement from STD for split to reduce dependency on Boost From 5a8818fec47faf17cf004cc6e3136f6c810c9012 Mon Sep 17 00:00:00 2001 From: Matt Williamson <87771120+mattw-nws@users.noreply.github.com> Date: Wed, 22 Mar 2023 18:24:26 +0000 Subject: [PATCH 2/2] --- include/utilities/CSV_Reader.h | 46 +++++++++++++++++----------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/include/utilities/CSV_Reader.h b/include/utilities/CSV_Reader.h index 341181bcb6..1ee13e7851 100644 --- a/include/utilities/CSV_Reader.h +++ b/include/utilities/CSV_Reader.h @@ -13,16 +13,16 @@ */ class CSVReader { - std::string fileName; - std::string delimeter; + std::string fileName; + std::string delimeter; public: - CSVReader(std::string filename, std::string delm = ",") : - fileName(filename), delimeter(delm) - { } + CSVReader(std::string filename, std::string delm = ",") : + fileName(filename), delimeter(delm) + { } - // Function to fetch data from a CSV File - std::vector > getData(); + // Function to fetch data from a CSV File + std::vector > getData(); }; /* @@ -31,7 +31,7 @@ class CSVReader */ inline std::vector > CSVReader::getData() { - std::ifstream file(fileName); + std::ifstream file(fileName); if(file.fail()){ /// \todo TODO: Return appropriate error @@ -40,27 +40,27 @@ inline std::vector > CSVReader::getData() /// \todo Potentially only output warning and fill array with sentinel values. } - std::vector > dataList; + std::vector > dataList; - std::string line = ""; - // Iterate through each line and split the content using delimeter - while (getline(file, line)) - { - // Consider more robust solution like https://stackoverflow.com/a/6089413/489116 - if ( line.size() && line[line.size()-1] == '\r' ) { + std::string line = ""; + // Iterate through each line and split the content using delimeter + while (getline(file, line)) + { + // Consider more robust solution like https://stackoverflow.com/a/6089413/489116 + if ( line.size() && line[line.size()-1] == '\r' ) { line = line.substr( 0, line.size() - 1 ); - } + } - std::vector vec; + std::vector vec; /// \todo Look into replacement from STD for split to reduce dependency on Boost - boost::algorithm::split(vec, line, boost::is_any_of(delimeter)); - dataList.push_back(vec); - } - // Close the File - file.close(); + boost::algorithm::split(vec, line, boost::is_any_of(delimeter)); + dataList.push_back(vec); + } + // Close the File + file.close(); - return dataList; + return dataList; } #endif //CSV_Reader_H