Orcus
Toggle main menu visibility
Loading...
Searching...
No Matches
include
orcus
sax_token_parser.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_TOKEN_PARSER_HPP
9
#define INCLUDED_ORCUS_SAX_TOKEN_PARSER_HPP
10
11
#include "sax_ns_parser.hpp"
12
#include "types.hpp"
13
14
#include <vector>
15
#include <algorithm>
16
#include <functional>
17
18
namespace
orcus {
19
20
class
tokens
;
21
22
class
ORCUS_PSR_DLLPUBLIC sax_token_handler_wrapper_base
23
{
24
protected
:
25
xml_declaration_t
m_declaration;
26
xml_token_element_t
m_elem;
27
const
tokens
& m_tokens;
28
29
xml_token_t tokenize(std::string_view name)
const
;
30
void
set_element(
const
sax_ns_parser_element
& elem);
31
32
public
:
33
sax_token_handler_wrapper_base(
const
tokens
& _tokens);
34
35
void
attribute(std::string_view name, std::string_view val);
36
void
attribute(
const
sax_ns_parser_attribute
& attr);
37
};
38
39
class
sax_token_handler
40
{
41
public
:
42
48
void
declaration
(
const
orcus::xml_declaration_t
& decl)
49
{
50
(void)decl;
51
}
52
59
void
start_element
(
const
orcus::xml_token_element_t
& elem)
60
{
61
(void)elem;
62
}
63
70
void
end_element
(
const
orcus::xml_token_element_t
& elem)
71
{
72
(void)elem;
73
}
74
89
void
characters
(std::string_view val,
bool
transient)
90
{
91
(void)val; (void)transient;
92
}
93
};
94
107
template
<
typename
HandlerT>
108
class
sax_token_parser
109
{
110
public
:
111
typedef
HandlerT handler_type;
112
113
sax_token_parser(
114
std::string_view content,
const
tokens
& _tokens,
115
xmlns_context
& ns_cxt, handler_type& handler);
116
117
~sax_token_parser() =
default
;
118
119
void
parse();
120
121
private
:
122
127
class
handler_wrapper :
public
sax_token_handler_wrapper_base
128
{
129
handler_type& m_handler;
130
131
public
:
132
handler_wrapper(
const
tokens
& _tokens, handler_type& handler) :
133
sax_token_handler_wrapper_base
(_tokens), m_handler(handler) {}
134
135
void
doctype(
const
sax::doctype_declaration
&) {}
136
137
void
start_declaration(std::string_view) {}
138
139
void
end_declaration(std::string_view)
140
{
141
m_handler.declaration(m_declaration);
142
m_elem.attrs.clear();
143
}
144
145
void
start_element(
const
sax_ns_parser_element
& elem)
146
{
147
set_element(elem);
148
m_handler.start_element(m_elem);
149
m_elem.attrs.clear();
150
}
151
152
void
end_element(
const
sax_ns_parser_element
& elem)
153
{
154
set_element(elem);
155
m_handler.end_element(m_elem);
156
}
157
158
void
characters(std::string_view val,
bool
transient)
159
{
160
m_handler.characters(val, transient);
161
}
162
};
163
164
private
:
165
handler_wrapper m_wrapper;
166
sax_ns_parser<handler_wrapper>
m_parser;
167
};
168
169
template
<
typename
HandlerT>
170
sax_token_parser<HandlerT>::sax_token_parser(
171
std::string_view content,
const
tokens
& _tokens,
xmlns_context
& ns_cxt, handler_type& handler) :
172
m_wrapper(_tokens, handler),
173
m_parser(content, ns_cxt, m_wrapper)
174
{
175
}
176
177
template
<
typename
HandlerT>
178
void
sax_token_parser<HandlerT>::parse()
179
{
180
m_parser.parse();
181
}
182
183
}
// namespace orcus
184
185
#endif
186
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
orcus::sax_ns_parser
Definition
sax_ns_parser.hpp:213
orcus::sax_token_handler_wrapper_base
Definition
sax_token_parser.hpp:23
orcus::sax_token_handler
Definition
sax_token_parser.hpp:40
orcus::sax_token_handler::declaration
void declaration(const orcus::xml_declaration_t &decl)
Definition
sax_token_parser.hpp:48
orcus::sax_token_handler::start_element
void start_element(const orcus::xml_token_element_t &elem)
Definition
sax_token_parser.hpp:59
orcus::sax_token_handler::end_element
void end_element(const orcus::xml_token_element_t &elem)
Definition
sax_token_parser.hpp:70
orcus::sax_token_handler::characters
void characters(std::string_view val, bool transient)
Definition
sax_token_parser.hpp:89
orcus::tokens
Definition
tokens.hpp:30
orcus::xmlns_context
Definition
xml_namespace.hpp:100
orcus::sax::doctype_declaration
Definition
sax_parser_base.hpp:37
orcus::sax_ns_parser_attribute
Definition
sax_ns_parser.hpp:35
orcus::sax_ns_parser_element
Definition
sax_ns_parser.hpp:21
orcus::xml_declaration_t
Definition
types.hpp:434
orcus::xml_token_element_t
Definition
types.hpp:148
Generated on
for Orcus by
1.17.0