8 #ifndef ORCUS_CSV_PARSER_HPP 9 #define ORCUS_CSV_PARSER_HPP 11 #include "csv_parser_base.hpp" 15 template<
typename _Handler>
19 typedef _Handler handler_type;
31 void parse_cell_with_quote(
const char* p0,
size_t len0);
36 void push_cell_value(
const char* p,
size_t n);
39 handler_type& m_handler;
42 template<
typename _Handler>
47 template<
typename _Handler>
51 const char* p = mp_char;
52 for (
size_t i = m_pos; i < m_length; ++i, ++p)
54 std::cout << std::endl;
57 m_handler.begin_parse();
60 m_handler.end_parse();
63 template<
typename _Handler>
66 m_handler.begin_row();
69 if (is_text_qualifier(cur_char()))
85 cout <<
"(LF)" << endl;
94 if (m_config.trim_cell_value)
99 template<
typename _Handler>
102 const char* p = mp_char;
105 while (c !=
'\n' && !is_delim(c))
117 push_cell_value(p, len);
120 template<
typename _Handler>
124 cout <<
"--- quoted cell" << endl;
127 assert(is_text_qualifier(c));
132 const char* p0 = mp_char;
134 for (; has_char(); next(), ++len)
138 cout <<
"'" << c <<
"'" << endl;
140 if (!is_text_qualifier(c))
146 if (has_next() && is_text_qualifier(next_char()))
149 parse_cell_with_quote(p0, len);
154 m_handler.cell(p0, len-1);
161 m_handler.cell(p0, len);
166 template<
typename _Handler>
171 cout <<
"--- parse cell with quote" << endl;
173 assert(is_text_qualifier(cur_char()));
177 m_cell_buf.append(p0, len0);
181 const char* p_cur = mp_char;
183 for (; has_char(); next(), ++cur_len)
187 cout <<
"'" << c <<
"'" << endl;
189 if (!is_text_qualifier(c))
192 if (has_next() && is_text_qualifier(next_char()))
195 m_cell_buf.append(p_cur, cur_len);
205 m_cell_buf.append(p_cur, cur_len);
207 m_handler.cell(m_cell_buf.get(), m_cell_buf.size());
214 throw csv::parse_error(
"stream ended prematurely while parsing quoted cell.");
217 template<
typename _Handler>
222 if (m_config.trim_cell_value)
225 for (
size_t i = 0; i < n; ++i, --len, ++p)
234 const char* p_end = p + (len-1);
235 for (; p != p_end; --p_end, --len)
243 m_handler.cell(p, len);
246 cout <<
"(cell:'" << std::string(p, len) <<
"')" << endl;
248 cout <<
"(cell:'')" << endl;
Definition: csv_parser_base.hpp:51
Definition: csv_parser_base.hpp:42
Definition: csv_parser.hpp:16
Definition: config.hpp:17
bool is_blank(char c) const
Definition: base64.hpp:15
Definition: csv_parser_base.hpp:33