LeechCraft  0.6.70-18450-gabe19ee3b0
Modular cross-platform feature rich live environment.
xmlnode.h
Go to the documentation of this file.
1 /**********************************************************************
2  * LeechCraft - modular cross-platform feature rich internet client.
3  * Copyright (C) 2006-2014 Georg Rudoy
4  *
5  * Distributed under the Boost Software License, Version 1.0.
6  * (See accompanying file LICENSE or copy at https://www.boost.org/LICENSE_1_0.txt)
7  **********************************************************************/
8 
9 #pragma once
10 
11 #include <utility>
12 #include <variant>
13 #include <QString>
14 #include <QVector>
15 #include "sllconfig.h"
16 
17 class QSize;
18 
19 namespace LC::Util
20 {
21  using TagAttrs = QVector<std::pair<QByteArray, QString>>;
22 
23  struct Tag;
24 
25  struct NoNode {};
26 
27  using Node = std::variant<Tag, QString, NoNode>;
28  using Nodes = QVector<Node>;
29 
33 
34  template<typename T>
35  concept XmlRepr = std::is_same_v<T, QString> || std::is_same_v<T, QByteArray>;
36 
37  struct NoDtd {};
38  struct Html5Dtd {};
39  struct CustomDtd { QString Dtd_; };
40  using Dtd = std::variant<NoDtd, Html5Dtd, CustomDtd>;
41 
43  {
44  bool Prolog_ = false;
45  Dtd Dtd_ = NoDtd {};
46  std::optional<int> Indent_ = {};
47  };
48 
49  struct Tag
50  {
51  QByteArray Name_;
53 
55 
56  UTIL_SLL_API static Tag WithText (const QByteArray& name, const QString& contents);
57  UTIL_SLL_API static Node WithTextNonEmpty (const QByteArray& name, const QString& contents);
58 
59  template<XmlRepr T = QString>
60  [[nodiscard]]
61  UTIL_SLL_API T Serialize (const TagSerializeConfig& = {}) const;
62 
63  UTIL_SLL_API Tag& WithAttr (QByteArray, QString) &&;
64  };
65 
66  namespace Tags
67  {
68  extern const Tag Br;
69 
70  UTIL_SLL_API Tag Html (Nodes&& children);
71  UTIL_SLL_API Tag Charset (const QString& charset);
72  UTIL_SLL_API Tag Title (const QString& title);
73  UTIL_SLL_API Tag Style (const QString& style);
74 
75  UTIL_SLL_API Tag Body (Nodes&& children);
76 
77  UTIL_SLL_API Tag Image (const QString& url);
78  UTIL_SLL_API Tag Image (const QString& url, const QSize&);
79  UTIL_SLL_API Tag Li (Nodes&& children);
80  UTIL_SLL_API Tag Ul (Nodes&& children);
81 
82  UTIL_SLL_API Tag P (Nodes&& children);
83 
84  UTIL_SLL_API Nodes TableGrid (size_t rows, size_t cols, const std::function<Nodes (size_t, size_t)>& cell);
85  }
86 }
Nodes TableGrid(size_t rows, size_t cols, const std::function< Nodes(size_t, size_t)> &cell)
Definition: xmlnode.cpp:170
static UTIL_SLL_API Node WithTextNonEmpty(const QByteArray &name, const QString &contents)
Definition: xmlnode.cpp:39
QVector< std::pair< QByteArray, QString > > TagAttrs
Definition: xmlnode.h:21
#define UTIL_SLL_API
Definition: sllconfig.h:16
std::optional< int > Indent_
Definition: xmlnode.h:46
concept XmlRepr
Definition: xmlnode.h:35
std::variant< Tag, QString, NoNode > Node
Definition: xmlnode.h:27
Tag Body(Nodes &&children)
Definition: xmlnode.cpp:134
Tag Html(Nodes &&children)
Definition: xmlnode.cpp:109
UTIL_SLL_API const Tag Br
Definition: xmlnode.cpp:107
Tag Charset(const QString &charset)
Definition: xmlnode.cpp:119
UTIL_SLL_API T Serialize(const TagSerializeConfig &={}) const
Q_DECL_IMPORT const QString Tags
std::variant< NoDtd, Html5Dtd, CustomDtd > Dtd
Definition: xmlnode.h:40
UTIL_SLL_API Tag & WithAttr(QByteArray, QString) &&
Definition: xmlnode.cpp:99
Tag Image(const QString &url)
Definition: xmlnode.cpp:139
Tag Title(const QString &title)
Definition: xmlnode.cpp:124
Tag Style(const QString &style)
Definition: xmlnode.cpp:129
Tag P(Nodes &&children)
Definition: xmlnode.cpp:165
static UTIL_SLL_API Tag WithText(const QByteArray &name, const QString &contents)
Definition: xmlnode.cpp:34
QByteArray Name_
Definition: xmlnode.h:51
Tag Ul(Nodes &&children)
Definition: xmlnode.cpp:160
constexpr auto operator+(RawStr< N1, Char > s1, CtString< N2, Char > s2) noexcept
Definition: ctstring.h:167
TagAttrs Attrs_
Definition: xmlnode.h:52
Nodes Children_
Definition: xmlnode.h:54
Tag Li(Nodes &&children)
Definition: xmlnode.cpp:155
QVector< Node > Nodes
Definition: xmlnode.h:28