minor refactoring

This commit is contained in:
ado 2021-02-06 21:08:59 +01:00
parent 5cd458e2bc
commit a1ca012203
2 changed files with 36 additions and 35 deletions

View File

@ -10,7 +10,6 @@
#include <vector> #include <vector>
// TODO rule of 5-3-1 // TODO rule of 5-3-1
// TODO threads
namespace ss { namespace ss {
template <typename... Matchers> template <typename... Matchers>
@ -261,7 +260,6 @@ private:
bool crlf; bool crlf;
bool escaped_eol(size_t size) { bool escaped_eol(size_t size) {
if constexpr (setup<Matchers...>::escape::enabled) {
const char* curr; const char* curr;
for (curr = next_line_buffer_ + size - 1; for (curr = next_line_buffer_ + size - 1;
curr >= next_line_buffer_ && curr >= next_line_buffer_ &&
@ -271,15 +269,10 @@ private:
return (next_line_buffer_ - curr + size) % 2 == 0; return (next_line_buffer_ - curr + size) % 2 == 0;
} }
return false;
}
bool unterminated_quote() { bool unterminated_quote() {
if constexpr (ss::setup<Matchers...>::quote::enabled) {
if (next_line_converter_.unterminated_quote()) { if (next_line_converter_.unterminated_quote()) {
return true; return true;
} }
}
return false; return false;
} }
@ -347,20 +340,24 @@ private:
size_t size = remove_eol(next_line_buffer_, ssize); size_t size = remove_eol(next_line_buffer_, ssize);
if constexpr (setup<Matchers...>::escape::enabled) {
while (escaped_eol(size)) { while (escaped_eol(size)) {
if (!append_line(file, next_line_buffer_, size)) { if (!append_line(file, next_line_buffer_, size)) {
return false; return false;
} }
} }
}
next_line_converter_.split(next_line_buffer_, delim_); next_line_converter_.split(next_line_buffer_, delim_);
if constexpr (setup<Matchers...>::quote::enabled) {
while (unterminated_quote()) { while (unterminated_quote()) {
if (!append_line(file, next_line_buffer_, size)) { if (!append_line(file, next_line_buffer_, size)) {
return false; return false;
} }
next_line_converter_.resplit(next_line_buffer_, size); next_line_converter_.resplit(next_line_buffer_, size);
} }
}
return true; return true;
} }

View File

@ -169,14 +169,6 @@ private:
} }
} }
void shift_if_escaped(line_ptr_type& curr) {
if constexpr (escape::enabled) {
if (escape::match(*curr)) {
shift_and_jump_escape();
}
}
}
template <typename Delim> template <typename Delim>
std::tuple<size_t, bool> match_delimiter(line_ptr_type begin, std::tuple<size_t, bool> match_delimiter(line_ptr_type begin,
const Delim& delim) { const Delim& delim) {
@ -207,12 +199,14 @@ private:
//////////////// ////////////////
void shift_and_set_current() { void shift_and_set_current() {
if (escaped_ > 0) {
if constexpr (!is_const_line) { if constexpr (!is_const_line) {
if (escaped_ > 0) {
std::copy_n(curr_ + escaped_, end_ - curr_, curr_); std::copy_n(curr_ + escaped_, end_ - curr_, curr_);
}
}
curr_ = end_ - escaped_; curr_ = end_ - escaped_;
return;
}
}
curr_ = end_;
} }
void shift_and_push() { void shift_and_push() {
@ -220,11 +214,21 @@ private:
split_input_.emplace_back(begin_, curr_); split_input_.emplace_back(begin_, curr_);
} }
void shift_if_escaped(line_ptr_type& curr) {
if constexpr (escape::enabled) {
if (escape::match(*curr)) {
shift_and_jump_escape();
}
}
}
void shift_and_jump_escape() { void shift_and_jump_escape() {
shift_and_set_current(); shift_and_set_current();
++end_; if constexpr (!is_const_line) {
++escaped_; ++escaped_;
} }
++end_;
}
void shift_push_and_start_next(size_t n) { void shift_push_and_start_next(size_t n) {
shift_and_push(); shift_and_push();
@ -381,7 +385,7 @@ private:
size_t escaped_{0}; size_t escaped_{0};
split_input split_input_; split_input split_input_;
template <typename ...> template <typename...>
friend class converter; friend class converter;
}; };