8#ifndef ORCUS_CSV_PARSER_HPP
9#define ORCUS_CSV_PARSER_HPP
11#include "csv_parser_base.hpp"
15template<
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;
42template<
typename _Handler>
47template<
typename _Handler>
48void csv_parser<_Handler>::parse()
51 for (
const char* p = mp_begin; p < mp_end; ++p)
53 std::cout << std::endl;
56 m_handler.begin_parse();
59 m_handler.end_parse();
62template<
typename _Handler>
63void csv_parser<_Handler>::row()
65 m_handler.begin_row();
68 if (is_text_qualifier(cur_char()))
84 cout <<
"(LF)" << endl;
95 if (m_config.trim_cell_value)
106template<
typename _Handler>
107void csv_parser<_Handler>::cell()
109 const char* p = mp_char;
112 while (c !=
'\n' && !is_delim(c))
124 push_cell_value(p, len);
127template<
typename _Handler>
128void csv_parser<_Handler>::quoted_cell()
131 cout <<
"--- quoted cell" << endl;
134 assert(is_text_qualifier(c));
139 const char* p0 = mp_char;
141 for (; has_char(); next(), ++len)
145 cout <<
"'" << c <<
"'" << endl;
147 if (!is_text_qualifier(c))
153 if (has_next() && is_text_qualifier(next_char()))
156 parse_cell_with_quote(p0, len);
161 m_handler.cell(p0, len-1,
false);
168 m_handler.cell(p0, len,
false);
171template<
typename _Handler>
172void csv_parser<_Handler>::parse_cell_with_quote(
const char* p0,
size_t len0)
176 cout <<
"--- parse cell with quote" << endl;
178 assert(is_text_qualifier(cur_char()));
182 m_cell_buf.append(p0, len0);
186 const char* p_cur = mp_char;
188 for (; has_char(); next(), ++cur_len)
192 cout <<
"'" << c <<
"'" << endl;
194 if (!is_text_qualifier(c))
197 if (has_next() && is_text_qualifier(next_char()))
200 m_cell_buf.append(p_cur, cur_len);
210 m_cell_buf.append(p_cur, cur_len);
212 m_handler.cell(m_cell_buf.get(), m_cell_buf.size(),
true);
219 throw csv::parse_error(
"stream ended prematurely while parsing quoted cell.");
222template<
typename _Handler>
223void csv_parser<_Handler>::push_cell_value(
const char* p,
size_t n)
227 if (m_config.trim_cell_value)
230 for (
size_t i = 0; i < n; ++i, --len, ++p)
239 const char* p_end = p + (len-1);
240 for (; p != p_end; --p_end, --len)
242 if (!is_blank(*p_end))
248 m_handler.cell(p, len,
false);
251 cout <<
"(cell:'" << std::string(p, len) <<
"')" << endl;
253 cout <<
"(cell:'')" << endl;
Definition: csv_parser_base.hpp:58
Definition: csv_parser_base.hpp:67
Definition: csv_parser.hpp:17
Definition: parser_base.hpp:40
Definition: config.hpp:19
Definition: csv_parser_base.hpp:37