[Enh #11] Import from Excel: trim names

This commit is contained in:
Martin Brodbeck 2019-02-25 08:57:10 +01:00
parent 65f5da45ec
commit 45fe7ea8bd
3 changed files with 25 additions and 2 deletions

View File

@ -1,4 +1,5 @@
#include "excelreader.h"
#include "utils.h"
#include <xlnt/xlnt.hpp>
#include <fstream>
@ -40,8 +41,10 @@ void ExcelReader::readSellersFromFile(const fs::path& filePath, Marketplace* mar
seller->createUuid();
seller->setSellerNo(row[0].value<int>());
seller->setNumArticlesOffered(row[1].value<int>());
seller->setFirstName(row[2].value<std::string>());
seller->setLastName(row[3].value<std::string>());
std::string firstName = row[2].value<std::string>();
seller->setFirstName(trim(firstName));
std::string lastName = row[3].value<std::string>();
seller->setLastName(trim(lastName));
market->getSellers().push_back(std::move(seller));
rowCount++;
}

View File

@ -44,3 +44,20 @@ std::optional<PrinterDevice> 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);
}

View File

@ -10,5 +10,8 @@
std::string formatCentAsEuroString(const int cent, int width = 10);
std::optional<PrinterDevice> 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