Orcus
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 INCLUDED_ORCUS_PARSER_BASE_HPP
9 #define INCLUDED_ORCUS_PARSER_BASE_HPP
10 
11 #include "orcus/env.hpp"
12 #include "orcus/exception.hpp"
13 
14 #include <string>
15 #include <cstdlib>
16 #include <cstddef>
17 
18 namespace orcus {
19 
20 class ORCUS_PSR_DLLPUBLIC parse_error : public general_error
21 {
22  std::ptrdiff_t m_offset;
23 protected:
24  parse_error(const std::string& msg, std::ptrdiff_t offset);
25  parse_error(const std::string& cls, const std::string& msg, std::ptrdiff_t offset);
26 
27  static std::string build_message(const char* msg_before, char c, const char* msg_after);
28  static std::string build_message(const char* msg_before, const char* p, size_t n, const char* msg_after);
29 
30 public:
31  std::ptrdiff_t offset() const;
32 };
33 
34 class ORCUS_PSR_DLLPUBLIC parser_base
35 {
36 protected:
37  const char* mp_begin;
38  const char* mp_char;
39  const char* mp_end;
40 
41 protected:
42  parser_base(const char* p, size_t n);
43 
44  bool has_char() const { return mp_char != mp_end; }
45  bool has_next() const { return (mp_char+1) != mp_end; }
46 
47  void next(size_t inc=1);
48  void prev(size_t dec=1);
49  char cur_char() const;
50  char next_char() const;
51 
52  void skip(const char* chars_to_skip);
53 
63  bool parse_expected(const char* expected);
64 
71  double parse_double();
72 
81  size_t remaining_size() const;
82 
88  std::ptrdiff_t offset() const;
89 };
90 
91 }
92 
93 #endif
94 
95 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Definition: exception.hpp:18
Definition: parser_base.hpp:34
Definition: parser_base.hpp:20
Definition: base64.hpp:15