diff --git a/include/ss/parser.hpp b/include/ss/parser.hpp index d8b19b5..11c78d6 100644 --- a/include/ss/parser.hpp +++ b/include/ss/parser.hpp @@ -10,7 +10,6 @@ #include // TODO rule of 5-3-1 -// TODO threads namespace ss { template @@ -261,24 +260,18 @@ private: bool crlf; bool escaped_eol(size_t size) { - if constexpr (setup::escape::enabled) { - const char* curr; - for (curr = next_line_buffer_ + size - 1; - curr >= next_line_buffer_ && - setup::escape::match(*curr); - --curr) { - } - return (next_line_buffer_ - curr + size) % 2 == 0; + const char* curr; + for (curr = next_line_buffer_ + size - 1; + curr >= next_line_buffer_ && + setup::escape::match(*curr); + --curr) { } - - return false; + return (next_line_buffer_ - curr + size) % 2 == 0; } bool unterminated_quote() { - if constexpr (ss::setup::quote::enabled) { - if (next_line_converter_.unterminated_quote()) { - return true; - } + if (next_line_converter_.unterminated_quote()) { + return true; } return false; } @@ -347,19 +340,23 @@ private: size_t size = remove_eol(next_line_buffer_, ssize); - while (escaped_eol(size)) { - if (!append_line(file, next_line_buffer_, size)) { - return false; + if constexpr (setup::escape::enabled) { + while (escaped_eol(size)) { + if (!append_line(file, next_line_buffer_, size)) { + return false; + } } } next_line_converter_.split(next_line_buffer_, delim_); - while (unterminated_quote()) { - if (!append_line(file, next_line_buffer_, size)) { - return false; + if constexpr (setup::quote::enabled) { + while (unterminated_quote()) { + if (!append_line(file, next_line_buffer_, size)) { + return false; + } + next_line_converter_.resplit(next_line_buffer_, size); } - next_line_converter_.resplit(next_line_buffer_, size); } return true; diff --git a/include/ss/splitter.hpp b/include/ss/splitter.hpp index dd0c0ec..5794cd4 100644 --- a/include/ss/splitter.hpp +++ b/include/ss/splitter.hpp @@ -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 std::tuple match_delimiter(line_ptr_type begin, const Delim& delim) { @@ -207,12 +199,14 @@ private: //////////////// 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_); + curr_ = end_ - escaped_; + return; } } - curr_ = end_ - escaped_; + curr_ = end_; } void shift_and_push() { @@ -220,10 +214,20 @@ private: 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() { shift_and_set_current(); + if constexpr (!is_const_line) { + ++escaped_; + } ++end_; - ++escaped_; } void shift_push_and_start_next(size_t n) { @@ -381,7 +385,7 @@ private: size_t escaped_{0}; split_input split_input_; - template + template friend class converter; };