update rapidcsv header

This commit is contained in:
Nathan-MV 2024-09-29 11:41:54 +00:00
parent f27018912c
commit 48955ab120

View file

@ -2,9 +2,9 @@
* rapidcsv.h * rapidcsv.h
* *
* URL: https://github.com/d99kris/rapidcsv * URL: https://github.com/d99kris/rapidcsv
* Version: 8.80 * Version: 8.84
* *
* Copyright (C) 2017-2023 Kristofer Berggren * Copyright (C) 2017-2024 Kristofer Berggren
* All rights reserved. * All rights reserved.
* *
* rapidcsv is distributed under the BSD 3-Clause license, see LICENSE for details. * rapidcsv is distributed under the BSD 3-Clause license, see LICENSE for details.
@ -1588,6 +1588,15 @@ namespace rapidcsv
{ {
quoted = !quoted; quoted = !quoted;
} }
else if (mSeparatorParams.mTrim)
{
// allow whitespace before first mQuoteChar
const auto firstQuote = std::find(cell.begin(), cell.end(), mSeparatorParams.mQuoteChar);
if (std::all_of(cell.begin(), firstQuote, [](int ch) { return isspace(ch); }))
{
quoted = !quoted;
}
}
cell += buffer[i]; cell += buffer[i];
} }
else if (buffer[i] == mSeparatorParams.mSeparator) else if (buffer[i] == mSeparatorParams.mSeparator)
@ -1654,13 +1663,28 @@ namespace rapidcsv
p_FileLength -= readLength; p_FileLength -= readLength;
} }
// Handle last line without linebreak // Handle last row / cell without linebreak
if (!cell.empty() || !row.empty()) if (row.empty() && cell.empty())
{
// skip empty trailing line
}
else
{ {
row.push_back(Unquote(Trim(cell))); row.push_back(Unquote(Trim(cell)));
if (mLineReaderParams.mSkipCommentLines && !row.at(0).empty() &&
(row.at(0)[0] == mLineReaderParams.mCommentPrefix))
{
// skip comment line
}
else
{
mData.push_back(row);
}
cell.clear(); cell.clear();
mData.push_back(row);
row.clear(); row.clear();
quoted = false;
} }
// Assume CR/LF if at least half the linebreaks have CR // Assume CR/LF if at least half the linebreaks have CR
@ -1725,7 +1749,8 @@ namespace rapidcsv
{ {
if (mSeparatorParams.mAutoQuote && if (mSeparatorParams.mAutoQuote &&
((itc->find(mSeparatorParams.mSeparator) != std::string::npos) || ((itc->find(mSeparatorParams.mSeparator) != std::string::npos) ||
(itc->find(' ') != std::string::npos))) (itc->find(' ') != std::string::npos) ||
(itc->find('\n') != std::string::npos)))
{ {
// escape quotes in string // escape quotes in string
std::string str = *itc; std::string str = *itc;