libwordring
simple_html.hpp
1 #pragma once
2 
3 #include <wordring/html/simple_node.hpp>
4 #include <wordring/html/simple_parser.hpp>
5 
6 #include <wordring/html/html_defs.hpp>
7 
8 #include <wordring/encoding/encoding_defs.hpp>
9 #include <wordring/whatwg/html/parsing/serializing.hpp>
10 
11 #include <wordring/tag_tree/tag_tree.hpp>
12 #include <wordring/compatibility.hpp>
13 
14 #include <iterator>
15 #include <type_traits>
16 
17 namespace wordring::html
18 {
20 
23 
26 
29 
32 
35 
38 
39  template <typename T> struct is_simple_tree : std::false_type {};
40 
41  template <> struct is_simple_tree<u8simple_tree> : public std::true_type {};
42  template <> struct is_simple_tree<u16simple_tree> : public std::true_type {};
43  template <> struct is_simple_tree<u32simple_tree> : public std::true_type {};
44 
45  template <typename T> constexpr bool is_simple_tree_v = is_simple_tree<T>::value;
46 
47  template <typename String>
48  using const_simple_tag_tree_iterator = typename wordring::detail::const_tag_tree_iterator<simple_node<String>>;
49 
50  template <typename String>
51  using simple_tag_tree_iterator = typename wordring::detail::tag_tree_iterator<simple_node<String>>;
52 
53  template<>
54  struct node_traits<simple_tag_tree_iterator<std::u8string>> : public simple_node_traits<simple_tag_tree_iterator<std::u8string>> {};
55 
56  template<>
57  struct node_traits<const_simple_tag_tree_iterator<std::u8string>> : public simple_node_traits<const_simple_tag_tree_iterator<std::u8string>> {};
58 
59  template<>
60  struct node_traits<simple_tag_tree_iterator<std::u16string>> : public simple_node_traits<simple_tag_tree_iterator<std::u16string>> {};
61 
62  template<>
63  struct node_traits<const_simple_tag_tree_iterator<std::u16string>> : public simple_node_traits<const_simple_tag_tree_iterator<std::u16string>> {};
64 
65  template<>
66  struct node_traits<simple_tag_tree_iterator<std::u32string>> : public simple_node_traits<simple_tag_tree_iterator<std::u32string>> {};
67 
68  template<>
69  struct node_traits<const_simple_tag_tree_iterator<std::u32string>> : public simple_node_traits<const_simple_tag_tree_iterator<std::u32string>> {};
70 
88  template <typename Container, typename ForwardIterator, typename std::enable_if_t<is_simple_tree_v<Container>, std::nullptr_t> = nullptr>
89  inline Container make_document(
90  ForwardIterator first,
91  ForwardIterator last,
92  encoding_name enc = encoding_name::UTF_8,
93  encoding_confidence_name confidence = encoding_confidence_name::tentative,
94  bool fragments_parser = false)
95  {
96  static_assert(std::is_base_of_v<std::forward_iterator_tag, typename std::iterator_traits<ForwardIterator>::iterator_category>);
97 
98  auto p = basic_simple_parser<Container, ForwardIterator>(confidence, enc, fragments_parser);
99  p.parse(first, last);
100  return p.get();
101  }
102 }
wordring::detail::tag_tree_iterator
Definition: tag_tree_iterator.hpp:19
wordring::tag_tree
HTML/XML 用の木
Definition: character_iterator.hpp:16
wordring::html::node_traits
HTMLノードへの操作を仲介するアダプタ
Definition: html/html_defs.hpp:29
wordring::html::is_simple_tree
Definition: simple_html.hpp:39
wordring::html::make_document
Container make_document(ForwardIterator first, ForwardIterator last, encoding_name enc=encoding_name::UTF_8, encoding_confidence_name confidence=encoding_confidence_name::tentative, bool fragments_parser=false)
文字列から HTML 文書を作成する便利関数
Definition: simple_html.hpp:89
wordring::html::simple_node_traits
node_traits のテンプレート特殊化
Definition: simple_traits.hpp:23
wordring::html
wordring::whatwg::html::to_string
void to_string(NodePointer it, OutputIterator out)
ノードを直列化する
Definition: serializing.hpp:159
wordring::html::basic_simple_parser
Definition: simple_parser.hpp:222
wordring::html::simple_node
Definition: simple_node.hpp:775
wordring::detail::const_tag_tree_iterator
Definition: tag_tree_iterator.hpp:22