1 #ifndef LIBFILEZILLA_XML_HEADER
2 #define LIBFILEZILLA_XML_HEADER
62 typedef std::function<bool(
callback_event type, std::string_view path, std::string_view name, std::string && value)>
callback_t;
74 bool parse(std::string_view data);
85 void set_limits(
size_t value_size_limit,
size_t path_size_limit);
88 bool FZ_PRIVATE_SYMBOL decode_ref();
89 bool FZ_PRIVATE_SYMBOL is_valid_tag_or_attr(std::string_view s)
const;
90 bool FZ_PRIVATE_SYMBOL normalize_value();
92 bool FZ_PRIVATE_SYMBOL parse_valid_utf8(std::string_view data);
93 bool FZ_PRIVATE_SYMBOL parse(
char const*
const begin,
char const*
const end);
94 void FZ_PRIVATE_SYMBOL set_error(std::string_view msg,
size_t offset);
96 bool FZ_PRIVATE_SYMBOL deduce_encoding(std::string_view & data);
136 std::vector<size_t> nodes_;
140 std::string converted_{};
142 size_t path_size_limit_{1024*1024};
143 size_t value_size_limit_{10*1024*1024};
146 size_t utf8_state_{};
147 uint32_t utf16_state_;
150 state s_{ state::content };
152 enum class encoding {
158 encoding encoding_{};
161 size_t tag_match_pos_{};
163 unsigned char dashes_;
193 bool parse(std::string_view data);
196 std::string get_error()
const;
203 std::string_view FZ_PRIVATE_SYMBOL apply_namespaces(std::string_view in);
204 bool FZ_PRIVATE_SYMBOL apply_namespace_to_path();
206 bool FZ_PRIVATE_SYMBOL on_callback(
callback_event type, std::string_view path, std::string_view name, std::string && value);
215 std::vector<size_t> nodes_;
216 std::vector<std::pair<std::string, std::string>> attributes_;
217 std::vector<std::tuple<size_t, std::string, std::string>> namespaces_;
218 bool needs_namespace_expansion_{};
229 void log(
callback_event type, std::string_view, std::string_view name, std::string_view
value);
232 virtual void on_line(std::string_view line) = 0;
235 void FZ_PRIVATE_SYMBOL finish_line();
236 void FZ_PRIVATE_SYMBOL print_line();
250 virtual void on_line(std::string_view line)
override;
The buffer class is a simple buffer where data can be appended at the end and consumed at the front....
Definition: buffer.hpp:27
Abstract interface for logging strings.
Definition: logger.hpp:51
A stremable XML parser that resolves namespace declarations and namespace prefixes.
Definition: xml.hpp:184
std::function< bool(callback_event type, std::string_view path, std::string_view name, std::string_view value)> raw_callback_t
Additional raw callback to look at events before namespace processing takes place.
Definition: xml.hpp:199
A streaming XML parser.
Definition: xml.hpp:54
void set_callback(callback_t &&cb)
std::string get_error() const
Returns an error description. Empty if parsing was stopped by a callback.
void set_limits(size_t value_size_limit, size_t path_size_limit)
bool parse(std::string_view data)
Processes the block of data. Can be partial.
std::function< bool(callback_event type, std::string_view path, std::string_view name, std::string &&value)> callback_t
Definition: xml.hpp:62
Pretty-prints XML as it is being parsed to a logger.
Definition: xml.hpp:245
A slow pretty printer for XML as it is being parsed.
Definition: xml.hpp:224
type
Definition: logger.hpp:16
The namespace used by libfilezilla.
Definition: apply.hpp:17
callback_event
Types of callbacks when parsing XML.
Definition: xml.hpp:24
@ close
An element is closed, passed name.
@ parsing_instruction
Parsing instruction, includes the <?xml?> declaration. Until first space in name, rest in value.
@ open
An element is opened, passed name.
@ attribute
Attribute in name and value.