Orcus
csv_parser_base.hpp
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This Source Code Form is subject to the terms of the Mozilla Public
4  * License, v. 2.0. If a copy of the MPL was not distributed with this
5  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
6  */
7 
8 #ifndef CSV_PARSER_BASE_HPP
9 #define CSV_PARSER_BASE_HPP
10 
11 #include "env.hpp"
12 #include "cell_buffer.hpp"
13 #include "parser_global.hpp"
14 #include "parser_base.hpp"
15 
16 #include <cstdlib>
17 #include <cstring>
18 #include <exception>
19 #include <string>
20 #include <cassert>
21 #include <sstream>
22 
23 #define ORCUS_DEBUG_CSV 0
24 
25 #if ORCUS_DEBUG_CSV
26 #include <iostream>
27 using std::cout;
28 using std::endl;
29 #endif
30 
31 namespace orcus { namespace csv {
32 
36 struct ORCUS_PSR_DLLPUBLIC parser_config
37 {
41  std::string delimiters;
42 
47 
53 
54  parser_config();
55 };
56 
57 class ORCUS_PSR_DLLPUBLIC parse_error : public std::exception
58 {
59  std::string m_msg;
60 public:
61  parse_error(const std::string& msg);
62  virtual ~parse_error() throw();
63  virtual const char* what() const throw();
64 };
65 
66 class ORCUS_PSR_DLLPUBLIC parser_base : public ::orcus::parser_base
67 {
68 protected:
69  const csv::parser_config& m_config;
70  cell_buffer m_cell_buf;
71 
72 protected:
73  parser_base(const char* p, size_t n, const parser_config& config);
74 
79  bool is_blank(char c) const;
80  bool is_delim(char c) const;
81  bool is_text_qualifier(char c) const;
82 
83  void skip_blanks();
84 
85 private:
86  void maybe_skip_bom();
87 };
88 
89 }}
90 
91 #endif
92 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
orcus::csv::parser_config::text_qualifier
char text_qualifier
Definition: csv_parser_base.hpp:46
orcus::csv::parser_base
Definition: csv_parser_base.hpp:66
orcus::config
Definition: config.hpp:18
orcus::csv::parse_error
Definition: csv_parser_base.hpp:57
orcus::csv::parser_config
Definition: csv_parser_base.hpp:36
orcus::cell_buffer
Definition: cell_buffer.hpp:21
orcus::parser_base
Definition: parser_base.hpp:39
orcus::csv::parser_config::delimiters
std::string delimiters
Definition: csv_parser_base.hpp:41
orcus::csv::parser_config::trim_cell_value
bool trim_cell_value
Definition: csv_parser_base.hpp:52