Skip to content

Commit

Permalink
CSV Parser 2.2.3
Browse files Browse the repository at this point in the history
Fix off-by-one issue in tests and update README
  • Loading branch information
vincentlaucsb committed May 26, 2024
1 parent d51f9e4 commit ade1e98
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 15 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ However, in reality we know that RFC 4180 is just a suggestion, and there's many
* Automatic delimiter guessing
* Ability to ignore comments in leading rows and elsewhere
* Ability to handle rows of different lengths
* Ability to handle arbitrary line endings (as long as they are some combination of carriage return and newline)

By default, rows of variable length are silently ignored, although you may elect to keep them or throw an error.

Expand Down
2 changes: 1 addition & 1 deletion include/csv.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
CSV for C++, version 2.2.2
CSV for C++, version 2.2.3
https://github.com/vincentlaucsb/csv-parser
MIT License
Expand Down
12 changes: 6 additions & 6 deletions single_include/csv.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once
/*
CSV for C++, version 2.2.2
CSV for C++, version 2.2.3
https://github.com/vincentlaucsb/csv-parser
MIT License
Expand Down Expand Up @@ -6627,7 +6627,7 @@ namespace csv {
return std::to_string(value);
#else
// TODO: Figure out why the below code doesn't work on clang
std::string result;
std::string result = "";

T integral_part;
T fractional_part = std::abs(std::modf(value, &integral_part));
Expand All @@ -6637,8 +6637,7 @@ namespace csv {
if (value < 0) result = "-";

if (integral_part == 0) {

result = "0";
result += "0";
}
else {
for (int n_digits = num_digits(integral_part); n_digits > 0; n_digits --) {
Expand Down Expand Up @@ -7065,8 +7064,8 @@ namespace csv {
case ParseFlags::NEWLINE:
this->data_pos++;

// Catches CRLF (or LFLF)
if (this->data_pos < in.size() && parse_flag(in[this->data_pos]) == ParseFlags::NEWLINE)
// Catches CRLF (or LFLF, CRCRLF, or any other non-sensical combination of newlines)
while (this->data_pos < in.size() && parse_flag(in[this->data_pos]) == ParseFlags::NEWLINE)
this->data_pos++;

// End of record -> Write record
Expand Down Expand Up @@ -7636,6 +7635,7 @@ namespace csv {
if (this->records->empty()) return this->end();
}

this->_n_rows++;
CSVReader::iterator ret(this, this->records->pop_front());
return ret;
}
Expand Down
12 changes: 6 additions & 6 deletions single_include_test/csv.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once
/*
CSV for C++, version 2.2.2
CSV for C++, version 2.2.3
https://github.com/vincentlaucsb/csv-parser
MIT License
Expand Down Expand Up @@ -6627,7 +6627,7 @@ namespace csv {
return std::to_string(value);
#else
// TODO: Figure out why the below code doesn't work on clang
std::string result;
std::string result = "";

T integral_part;
T fractional_part = std::abs(std::modf(value, &integral_part));
Expand All @@ -6637,8 +6637,7 @@ namespace csv {
if (value < 0) result = "-";

if (integral_part == 0) {

result = "0";
result += "0";
}
else {
for (int n_digits = num_digits(integral_part); n_digits > 0; n_digits --) {
Expand Down Expand Up @@ -7065,8 +7064,8 @@ namespace csv {
case ParseFlags::NEWLINE:
this->data_pos++;

// Catches CRLF (or LFLF)
if (this->data_pos < in.size() && parse_flag(in[this->data_pos]) == ParseFlags::NEWLINE)
// Catches CRLF (or LFLF, CRCRLF, or any other non-sensical combination of newlines)
while (this->data_pos < in.size() && parse_flag(in[this->data_pos]) == ParseFlags::NEWLINE)
this->data_pos++;

// End of record -> Write record
Expand Down Expand Up @@ -7636,6 +7635,7 @@ namespace csv {
if (this->records->empty()) return this->end();
}

this->_n_rows++;
CSVReader::iterator ret(this, this->records->pop_front());
return ret;
}
Expand Down
4 changes: 2 additions & 2 deletions tests/test_round_trip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ TEST_CASE("Simple Buffered Integer Round Trip Test", "[test_roundtrip_int]") {

const size_t n_rows = 1000000;

for (size_t i = 0; i <= n_rows; i++) {
for (size_t i = 0; i < n_rows; i++) {
auto str = internals::to_string(i);
writer << std::array<csv::string_view, 5>({str, str, str, str, str});
}
Expand Down Expand Up @@ -49,7 +49,7 @@ TEST_CASE("Simple Integer Round Trip Test", "[test_roundtrip_int]") {

const size_t n_rows = 1000000;

for (size_t i = 0; i <= n_rows; i++) {
for (size_t i = 0; i < n_rows; i++) {
auto str = internals::to_string(i);
writer << std::array<csv::string_view, 5>({ str, str, str, str, str });
}
Expand Down

0 comments on commit ade1e98

Please sign in to comment.