diff --git a/src/core/excelreader.cpp b/src/core/excelreader.cpp index 37e2d80..c388d3e 100644 --- a/src/core/excelreader.cpp +++ b/src/core/excelreader.cpp @@ -1,4 +1,5 @@ #include "excelreader.h" +#include "utils.h" #include #include @@ -40,8 +41,10 @@ void ExcelReader::readSellersFromFile(const fs::path& filePath, Marketplace* mar seller->createUuid(); seller->setSellerNo(row[0].value()); seller->setNumArticlesOffered(row[1].value()); - seller->setFirstName(row[2].value()); - seller->setLastName(row[3].value()); + std::string firstName = row[2].value(); + seller->setFirstName(trim(firstName)); + std::string lastName = row[3].value(); + seller->setLastName(trim(lastName)); market->getSellers().push_back(std::move(seller)); rowCount++; } diff --git a/src/core/utils.cpp b/src/core/utils.cpp index b983423..ccb0d34 100644 --- a/src/core/utils.cpp +++ b/src/core/utils.cpp @@ -44,3 +44,20 @@ std::optional convertToPosPrinterDevice(const std::string& device return printerDevice; } + +std::string& ltrim(std::string& str, const std::string& chars) +{ + str.erase(0, str.find_first_not_of(chars)); + return str; +} + +std::string& rtrim(std::string& str, const std::string& chars) +{ + str.erase(str.find_last_not_of(chars) + 1); + return str; +} + +std::string& trim(std::string& str, const std::string& chars) +{ + return ltrim(rtrim(str, chars), chars); +} \ No newline at end of file diff --git a/src/core/utils.h b/src/core/utils.h index ff15359..f227da4 100644 --- a/src/core/utils.h +++ b/src/core/utils.h @@ -10,5 +10,8 @@ std::string formatCentAsEuroString(const int cent, int width = 10); std::optional convertToPosPrinterDevice(const std::string& vendor, const std::string& endpoint); +std::string& ltrim(std::string& str, const std::string& chars = "\t\n\v\f\r "); +std::string& rtrim(std::string& str, const std::string& chars = "\t\n\v\f\r "); +std::string& trim(std::string& str, const std::string& chars = "\t\n\v\f\r "); #endif