mirror of
https://github.com/red0124/ssp.git
synced 2025-12-14 21:59:55 +01:00
add mismatched quote error, update error handling for splitter, add unit tests, update test_helpers buffer
This commit is contained in:
@@ -127,11 +127,6 @@ public:
|
||||
no_void_validator_tup_t<Ts...> convert(
|
||||
line_ptr_type line, const std::string& delim = default_delimiter) {
|
||||
input_ = split(line, delim);
|
||||
if (!splitter_.valid()) {
|
||||
set_error_line_not_split();
|
||||
no_void_validator_tup_t<Ts...> ret{};
|
||||
return ret;
|
||||
}
|
||||
return convert<Ts...>(input_);
|
||||
}
|
||||
|
||||
@@ -191,6 +186,7 @@ public:
|
||||
}
|
||||
|
||||
void set_error_mode(error_mode mode) {
|
||||
splitter_.set_error_mode(mode);
|
||||
error_mode_ = mode;
|
||||
}
|
||||
|
||||
@@ -234,10 +230,10 @@ private:
|
||||
return error;
|
||||
}
|
||||
|
||||
void set_error_line_not_split() {
|
||||
void set_error_unterminated_quote() {
|
||||
if (error_mode_ == error_mode::error_string) {
|
||||
string_error_.clear();
|
||||
string_error_.append("line not split correctly");
|
||||
string_error_.append(splitter_.error_msg());
|
||||
} else {
|
||||
bool_error_ = true;
|
||||
}
|
||||
@@ -283,11 +279,19 @@ private:
|
||||
template <typename... Ts>
|
||||
no_void_validator_tup_t<Ts...> convert_impl(const split_input& elems) {
|
||||
clear_error();
|
||||
|
||||
if (!splitter_.valid()) {
|
||||
set_error_unterminated_quote();
|
||||
no_void_validator_tup_t<Ts...> ret{};
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (sizeof...(Ts) != elems.size()) {
|
||||
set_error_number_of_colums(sizeof...(Ts), elems.size());
|
||||
no_void_validator_tup_t<Ts...> ret{};
|
||||
return ret;
|
||||
}
|
||||
|
||||
return extract_tuple<Ts...>(elems);
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
// TODO rule of 5-3-1
|
||||
// TODO threads
|
||||
namespace ss {
|
||||
|
||||
template <typename... Matchers>
|
||||
|
||||
@@ -119,7 +119,7 @@ public:
|
||||
}
|
||||
|
||||
const split_input& split(line_ptr_type new_line,
|
||||
const std::string& delimiter = default_delimiter) {
|
||||
const std::string& delimiter = default_delimiter) {
|
||||
output_.clear();
|
||||
return resplit(new_line, -1, delimiter);
|
||||
}
|
||||
@@ -131,8 +131,9 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
const split_input& resplit(line_ptr_type new_line, ssize_t new_size,
|
||||
const std::string& delimiter = default_delimiter) {
|
||||
const split_input& resplit(
|
||||
line_ptr_type new_line, ssize_t new_size,
|
||||
const std::string& delimiter = default_delimiter) {
|
||||
line_ = new_line;
|
||||
|
||||
// resplitting, continue from last slice
|
||||
@@ -175,6 +176,16 @@ private:
|
||||
}
|
||||
}
|
||||
|
||||
void set_error_mismatched_quote(size_t n) {
|
||||
if (error_mode_ == error_mode::error_string) {
|
||||
string_error_.clear();
|
||||
string_error_.append("mismatched quote at position: " +
|
||||
std::to_string(n));
|
||||
} else {
|
||||
bool_error_ = true;
|
||||
}
|
||||
}
|
||||
|
||||
void set_error_unterminated_quote() {
|
||||
unterminated_quote_ = true;
|
||||
if (error_mode_ == error_mode::error_string) {
|
||||
@@ -186,9 +197,11 @@ private:
|
||||
}
|
||||
|
||||
void set_error_invalid_resplit() {
|
||||
unterminated_quote_ = false;
|
||||
if (error_mode_ == error_mode::error_string) {
|
||||
string_error_.clear();
|
||||
string_error_.append("invalid_resplit");
|
||||
string_error_.append("invalid resplit, new line must be longer"
|
||||
"than the end of the last slice");
|
||||
} else {
|
||||
bool_error_ = true;
|
||||
}
|
||||
@@ -388,9 +401,10 @@ private:
|
||||
// eg no trim: ...,"hello"\0 -> hello
|
||||
output_.emplace_back(begin_, curr_);
|
||||
} else {
|
||||
// missmatched quote
|
||||
// mismatched quote
|
||||
// eg: ...,"hel"lo,... -> error
|
||||
// or not
|
||||
set_error_mismatched_quote(end_ - line_);
|
||||
output_.emplace_back(line_, begin_);
|
||||
}
|
||||
state_ = state::finished;
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user