Orcus
Toggle main menu visibility
Loading...
Searching...
No Matches
include
orcus
sax_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_SAX_PARSER_BASE_HPP
9
#define INCLUDED_ORCUS_SAX_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 <cassert>
17
#include <cstdlib>
18
#include <exception>
19
#include <sstream>
20
#include <memory>
21
22
#define ORCUS_DEBUG_SAX_PARSER 0
23
24
#if ORCUS_DEBUG_SAX_PARSER
25
#include <iostream>
26
using
std::cout;
27
using
std::endl;
28
#endif
29
30
namespace
orcus {
namespace
sax {
31
36
struct
doctype_declaration
37
{
38
enum class
keyword_type { dtd_public, dtd_private };
39
40
keyword_type keyword;
41
std::string_view root_element;
42
std::string_view fpi;
43
std::string_view uri;
44
};
45
57
ORCUS_PSR_DLLPUBLIC
char
decode_xml_encoded_char(
const
char
* p,
size_t
n);
58
70
ORCUS_PSR_DLLPUBLIC std::string decode_xml_unicode_char(
const
char
* p,
size_t
n);
71
76
struct
parser_element
77
{
79
std::string_view
ns
;
81
std::string_view
name
;
83
std::ptrdiff_t
begin_pos
;
85
std::ptrdiff_t
end_pos
;
86
};
87
95
struct
parser_attribute
96
{
98
std::string_view
ns
;
100
std::string_view
name
;
102
std::string_view
value
;
104
bool
transient
;
105
};
106
107
class
ORCUS_PSR_DLLPUBLIC parser_base :
public
::orcus::parser_base
108
{
109
struct
impl;
110
std::unique_ptr<impl> mp_impl;
111
112
parser_base() =
delete
;
113
parser_base(
const
parser_base&) =
delete
;
114
parser_base& operator=(
const
parser_base&) =
delete
;
115
protected
:
116
size_t
m_nest_level;
117
size_t
m_buffer_pos;
118
bool
m_root_elem_open:1;
119
120
protected
:
121
parser_base(
const
char
* content,
size_t
size);
122
~parser_base();
123
124
void
next_check()
125
{
126
next();
127
if
(!has_char())
128
throw
malformed_xml_error
(
"xml stream ended prematurely."
,
offset
());
129
}
130
131
void
nest_up() { ++m_nest_level; }
132
void
nest_down()
133
{
134
if
(m_nest_level == 0)
135
throw
malformed_xml_error
(
"incorrect nesting in xml stream"
,
offset
());
136
137
--m_nest_level;
138
}
139
140
void
inc_buffer_pos();
141
void
reset_buffer_pos() { m_buffer_pos = 0; }
142
143
void
has_char_throw(
const
char
* msg)
const
144
{
145
if
(!has_char())
146
throw
malformed_xml_error
(msg,
offset
());
147
}
148
149
char
cur_char_checked()
const
150
{
151
if
(!has_char())
152
throw
malformed_xml_error
(
"xml stream ended prematurely."
,
offset
());
153
154
return
*mp_char;
155
}
156
157
char
next_and_char()
158
{
159
next();
160
#if ORCUS_DEBUG_SAX_PARSER
161
if
(mp_char >= mp_end)
162
throw
malformed_xml_error
(
"xml stream ended prematurely."
,
offset
());
163
#endif
164
return
*mp_char;
165
}
166
167
char
next_char_checked()
168
{
169
next();
170
if
(!has_char())
171
throw
malformed_xml_error
(
"xml stream ended prematurely."
,
offset
());
172
173
return
*mp_char;
174
}
175
176
cell_buffer
& get_cell_buffer();
177
178
void
comment();
179
180
void
expects_next(
const
char
* p,
size_t
n);
181
182
void
parse_encoded_char(
cell_buffer
& buf);
183
void
value_with_encoded_char(
cell_buffer
& buf, std::string_view& str,
char
quote_char);
184
196
bool
value
(std::string_view& str,
bool
decode);
197
198
void
name(std::string_view& str);
199
void
element_name(
parser_element
& elem, std::ptrdiff_t begin_pos);
200
void
attribute_name(std::string_view& attr_ns, std::string_view& attr_name);
201
void
characters_with_encoded_char(
cell_buffer
& buf);
202
};
203
204
}}
205
206
#endif
207
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
orcus::cell_buffer
Definition
cell_buffer.hpp:22
orcus::malformed_xml_error
Definition
exception.hpp:121
orcus::parser_base
Definition
parser_base.hpp:23
orcus::parser_base::offset
std::ptrdiff_t offset() const
orcus::sax::parser_base::value
bool value(std::string_view &str, bool decode)
orcus::sax::doctype_declaration
Definition
sax_parser_base.hpp:37
orcus::sax::parser_attribute
Definition
sax_parser_base.hpp:96
orcus::sax::parser_attribute::name
std::string_view name
Definition
sax_parser_base.hpp:100
orcus::sax::parser_attribute::ns
std::string_view ns
Definition
sax_parser_base.hpp:98
orcus::sax::parser_attribute::value
std::string_view value
Definition
sax_parser_base.hpp:102
orcus::sax::parser_attribute::transient
bool transient
Definition
sax_parser_base.hpp:104
orcus::sax::parser_element
Definition
sax_parser_base.hpp:77
orcus::sax::parser_element::name
std::string_view name
Definition
sax_parser_base.hpp:81
orcus::sax::parser_element::begin_pos
std::ptrdiff_t begin_pos
Definition
sax_parser_base.hpp:83
orcus::sax::parser_element::end_pos
std::ptrdiff_t end_pos
Definition
sax_parser_base.hpp:85
orcus::sax::parser_element::ns
std::string_view ns
Definition
sax_parser_base.hpp:79
Generated on
for Orcus by
1.17.0