mirror of
https://github.com/red0124/ssp.git
synced 2025-01-23 04:55:20 +01:00
Fix resplit segmentation fault, fix issues when working with empty files
This commit is contained in:
parent
a7a97b3ba8
commit
956156b412
@ -37,6 +37,10 @@ public:
|
|||||||
: file_name_{file_name}, reader_{file_name_, delim} {
|
: file_name_{file_name}, reader_{file_name_, delim} {
|
||||||
if (reader_.file_) {
|
if (reader_.file_) {
|
||||||
read_line();
|
read_line();
|
||||||
|
if (eof_) {
|
||||||
|
set_error_eof_reached();
|
||||||
|
return;
|
||||||
|
}
|
||||||
if constexpr (ignore_header) {
|
if constexpr (ignore_header) {
|
||||||
ignore_next();
|
ignore_next();
|
||||||
} else {
|
} else {
|
||||||
|
@ -78,11 +78,10 @@ private:
|
|||||||
const std::string& delimiter = default_delimiter) {
|
const std::string& delimiter = default_delimiter) {
|
||||||
|
|
||||||
// resplitting, continue from last slice
|
// resplitting, continue from last slice
|
||||||
if constexpr (!quote::enabled || !multiline::enabled) {
|
if (!quote::enabled || !multiline::enabled || split_data_.empty() ||
|
||||||
if (split_data_.empty() || !unterminated_quote()) {
|
!unterminated_quote()) {
|
||||||
set_error_invalid_resplit();
|
set_error_invalid_resplit();
|
||||||
return split_data_;
|
return split_data_;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto [old_line, old_begin] = *std::prev(split_data_.end());
|
const auto [old_line, old_begin] = *std::prev(split_data_.end());
|
||||||
@ -90,7 +89,6 @@ private:
|
|||||||
|
|
||||||
// safety measure
|
// safety measure
|
||||||
if (new_size != -1 && static_cast<size_t>(new_size) < begin) {
|
if (new_size != -1 && static_cast<size_t>(new_size) < begin) {
|
||||||
unterminated_quote_ = false;
|
|
||||||
set_error_invalid_resplit();
|
set_error_invalid_resplit();
|
||||||
return split_data_;
|
return split_data_;
|
||||||
}
|
}
|
||||||
|
@ -1099,7 +1099,6 @@ TEST_CASE("splitter test invalid splits") {
|
|||||||
char new_line[] = "some";
|
char new_line[] = "some";
|
||||||
c.resplit(new_line, strlen(new_line));
|
c.resplit(new_line, strlen(new_line));
|
||||||
CHECK_FALSE(s.valid());
|
CHECK_FALSE(s.valid());
|
||||||
CHECK_FALSE(s.unterminated_quote());
|
|
||||||
CHECK_FALSE(s.error_msg().empty());
|
CHECK_FALSE(s.error_msg().empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1132,7 +1131,6 @@ TEST_CASE("splitter test invalid splits with exceptions") {
|
|||||||
// invalid resplit
|
// invalid resplit
|
||||||
char new_line[] = "some";
|
char new_line[] = "some";
|
||||||
REQUIRE_EXCEPTION(c.resplit(new_line, strlen(new_line)));
|
REQUIRE_EXCEPTION(c.resplit(new_line, strlen(new_line)));
|
||||||
CHECK_FALSE(s.unterminated_quote());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("splitter test with trim_left") {
|
TEST_CASE("splitter test with trim_left") {
|
||||||
|
Loading…
Reference in New Issue
Block a user