Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
mattw-nws committed Mar 28, 2023
1 parent 1e57593 commit f6768d0
Showing 1 changed file with 23 additions and 23 deletions.
46 changes: 23 additions & 23 deletions include/utilities/CSV_Reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::vector<std::string> > getData();
// Function to fetch data from a CSV File
std::vector<std::vector<std::string> > getData();
};

/*
Expand All @@ -31,7 +31,7 @@ class CSVReader
*/
inline std::vector<std::vector<std::string> > CSVReader::getData()
{
std::ifstream file(fileName);
std::ifstream file(fileName);

if(file.fail()){
/// \todo TODO: Return appropriate error
Expand All @@ -40,27 +40,27 @@ inline std::vector<std::vector<std::string> > CSVReader::getData()
/// \todo Potentially only output warning and fill array with sentinel values.
}

std::vector<std::vector<std::string> > dataList;
std::vector<std::vector<std::string> > 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<std::string> vec;
std::vector<std::string> 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

0 comments on commit f6768d0

Please sign in to comment.