6 #include <wordring/html/html_defs.hpp>
8 #include <wordring/html/simple_node.hpp>
9 #include <wordring/html/simple_traits.hpp>
11 #include <wordring/whatwg/html/parsing/tree_construction_dispatcher.hpp>
12 #include <wordring/whatwg/encoding/api.hpp>
15 #include <type_traits>
31 template <
typename T,
typename Container>
40 using container = Container;
42 using string_type =
typename traits::string_type;
43 using node_type =
typename traits::node_type;
44 using node_pointer =
typename traits::node_pointer;
46 using document_type =
typename traits::document_type;
47 using document_type_type =
typename traits::document_type_type;
48 using document_fragment_type =
typename traits::document_fragment_type;
49 using element_type =
typename traits::element_type;
50 using text_type =
typename traits::text_type;
51 using processing_instruction_type =
typename traits::processing_instruction_type;
52 using comment_type =
typename traits::comment_type;
54 using attribute_type =
typename traits::attribute_type;
55 using attribute_pointer =
typename traits::attribute_pointer;
62 encoding_confidence_name confidence = encoding_confidence_name::irrelevant,
63 encoding_name enc =
static_cast<encoding_name
>(0),
64 bool fragments_parser =
false)
65 :
base_type(confidence, enc, fragments_parser)
67 m_document = m_c.insert(m_c.end(), document_type());
68 m_temporary = m_c.insert(m_c.end(), node_type());
73 void clear(encoding_confidence_name confidence, encoding_name enc)
77 m_document = m_c.insert(m_c.end(), document_type());
78 m_temporary = m_c.insert(m_c.end(), node_type());
95 node_pointer insert_document_type(node_pointer pos, document_type_type&& doctype)
97 return m_c.insert(pos, std::move(doctype));
109 node_pointer create_element(node_pointer doc, std::u32string name, ns_name ns)
111 return m_c.insert(m_temporary.end(), element_type(ns, string_type(), encoding_cast<string_type>(name)));
114 node_pointer create_element(node_pointer doc, tag_name name, ns_name ns)
116 return m_c.insert(m_temporary.end(), element_type(ns, string_type(), name));
119 node_pointer insert_element(node_pointer pos, node_pointer it)
121 return m_c.move(pos, it);
124 node_pointer get_node_document(node_pointer it)
149 void append_attribute(node_pointer it, ns_name ns, std::u32string
const& prefix, std::u32string
const& name, std::u32string
const& value)
151 it->push_back(attribute_type(ns, encoding_cast<string_type>(prefix), encoding_cast<string_type>(name), encoding_cast<string_type>(value)));
157 bool contains(node_pointer it, ns_name ns, std::u32string
const& prefix, std::u32string
const& name)
159 return it->contains(ns, encoding_cast<string_type>(prefix), encoding_cast<string_type>(name));
166 node_pointer insert_text(node_pointer pos, text_type&& text)
168 return m_c.insert(pos, std::move(text));
175 node_pointer insert_comment(node_pointer pos, comment_type&& comment)
177 return m_c.insert(pos, std::move(comment));
208 node_pointer m_document;
209 node_pointer m_temporary;
221 template <
typename Container,
typename ForwardIterator>
226 using container = Container;
227 using iterator = ForwardIterator;
229 static_assert(std::is_base_of_v<std::forward_iterator_tag,
typename std::iterator_traits<iterator>::iterator_category>);
239 encoding_confidence_name confidence = encoding_confidence_name::irrelevant,
240 encoding_name enc =
static_cast<encoding_name
>(0),
241 bool fragments_parser =
false)
242 :
base_type(confidence, enc, fragments_parser)
243 , m_updated_encoding_name(static_cast<encoding_name>(0))
251 void clear(encoding_confidence_name confidence, encoding_name enc)
254 m_updated_encoding_name =
static_cast<encoding_name
>(0);
264 void parse(iterator first, iterator last)
266 if constexpr (
sizeof(*first) == 4)
268 while (first != last)
274 else if constexpr (
sizeof(*first) == 2)
277 encoding_cast(first, last, std::back_inserter(s));
278 for (char32_t cp : s) push_back(cp);
280 else if constexpr (
sizeof(*first) == 1)
286 if (base_type::m_encoding_name ==
static_cast<encoding_name
>(0)) base_type::m_encoding_name = encoding_name::UTF_8;
287 dec =
text_decoder(base_type::m_encoding_name,
false,
false);
288 std::u32string s = dec.
decode(first, last);
292 if (m_updated_encoding_name !=
static_cast<encoding_name
>(0))
294 clear(base_type::m_encoding_confidence, m_updated_encoding_name);
304 base_type::m_c.erase(base_type::m_temporary);
306 std::swap(base_type::m_c, c);
312 void on_change_encoding(encoding_name name)
314 m_updated_encoding_name = name;
318 encoding_name m_updated_encoding_name;
324 template <
typename Container>