Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate trimquote fix #155

Merged
merged 3 commits into from
Jan 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ if(RAPIDCSV_BUILD_TESTS)
add_unit_test(test093)
add_unit_test(test094)
add_unit_test(test095)
add_unit_test(test096)

# perf tests
add_perf_test(ptest001)
Expand Down
13 changes: 11 additions & 2 deletions src/rapidcsv.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
* rapidcsv.h
*
* URL: https://github.com/d99kris/rapidcsv
* Version: 8.80
* Version: 8.81
*
* Copyright (C) 2017-2023 Kristofer Berggren
* Copyright (C) 2017-2024 Kristofer Berggren
* All rights reserved.
*
* rapidcsv is distributed under the BSD 3-Clause license, see LICENSE for details.
Expand Down Expand Up @@ -1588,6 +1588,15 @@ namespace rapidcsv
{
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];
}
else if (buffer[i] == mSeparatorParams.mSeparator)
Expand Down
39 changes: 39 additions & 0 deletions tests/test096.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// test096.cpp - read trimmed quoted cell values

#include <rapidcsv.h>
#include "unittest.h"

int main()
{
int rv = 0;

std::string csv =
"-, A,B , C \n"
" \"1\",\"3,\" , \"9,\" , \"81,\"\n"
"\"2\" ,\"4\" , \"16\", \"256\" \n"
;

std::string path = unittest::TempPath();
unittest::WriteFile(path, csv);

try
{
rapidcsv::Document doc(path, rapidcsv::LabelParams(0, 0), rapidcsv::SeparatorParams(',', true));
unittest::ExpectEqual(std::string, doc.GetCell<std::string>("A", "1"), "3,");
unittest::ExpectEqual(std::string, doc.GetCell<std::string>("B", "1"), "9,");
unittest::ExpectEqual(std::string, doc.GetCell<std::string>("C", "1"), "81,");

unittest::ExpectEqual(std::string, doc.GetCell<std::string>("A", "2"), "4");
unittest::ExpectEqual(std::string, doc.GetCell<std::string>("B", "2"), "16");
unittest::ExpectEqual(std::string, doc.GetCell<std::string>("C", "2"), "256");
}
catch (const std::exception& ex)
{
std::cout << ex.what() << std::endl;
rv = 1;
}

unittest::DeleteFile(path);

return rv;
}
Loading