2
0
mirror of https://github.com/Laupetin/OpenAssetTools.git synced 2025-07-01 16:51:56 +00:00

chore: trim csv reader values

This commit is contained in:
Jan
2024-10-06 17:10:50 +02:00
parent d814fe7b95
commit d2b95b4ebe
3 changed files with 53 additions and 6 deletions

View File

@ -1,5 +1,7 @@
#include "CsvStream.h"
#include "Utils/StringUtils.h"
#include <cstdlib>
#include <sstream>
@ -110,13 +112,17 @@ bool CsvInputStream::EmitNextRow(const std::function<void(std::string)>& cb) con
auto c = m_stream.get();
const auto isEof = c == EOF;
std::ostringstream col;
auto content = false;
while (c != EOF)
{
if (c == CSV_SEPARATOR)
{
cb(col.str());
auto value = col.str();
utils::StringTrimR(value);
cb(std::move(value));
col.clear();
col.str(std::string());
content = false;
}
else if (c == '\r')
{
@ -129,8 +135,14 @@ bool CsvInputStream::EmitNextRow(const std::function<void(std::string)>& cb) con
{
break;
}
else if (isspace(c))
{
if (content)
col << static_cast<char>(c);
}
else
{
content = true;
col << static_cast<char>(c);
}
@ -139,7 +151,9 @@ bool CsvInputStream::EmitNextRow(const std::function<void(std::string)>& cb) con
if (!isEof)
{
cb(col.str());
auto value = col.str();
utils::StringTrimR(value);
cb(std::move(value));
}
return !isEof;