9#include "QXmppGlobal.h"
20class QXmlStreamWriter;
23namespace QXmpp::Private {
27 template<
class T, std::size_t N, std::size_t... I>
28 constexpr std::array<std::remove_cv_t<T>, N>
29 to_array_impl(T (&&a)[N], std::index_sequence<I...>)
31 return { { std::move(a[I])... } };
35template<
class T, std::
size_t N>
36constexpr std::array<std::remove_cv_t<T>, N> to_array(T (&&a)[N])
38 return detail::to_array_impl(std::move(a), std::make_index_sequence<N> {});
42inline auto toString60(QStringView s)
44#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
50inline auto toString65(QStringView s)
52#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)
60#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)
61#define QSL65(text) u"" text
63#define QSL65(text) QStringLiteral(text)
67template<
typename Enum, std::
size_t N>
68std::optional<Enum> enumFromString(
const std::array<QStringView, N> &values, QStringView str)
70 auto itr = std::find(values.begin(), values.end(), str);
71 if (itr != values.end()) {
72 return Enum(std::distance(values.begin(), itr));
78void writeOptionalXmlAttribute(QXmlStreamWriter *stream, QStringView name, QStringView value);
79void writeXmlTextElement(QXmlStreamWriter *stream, QStringView name, QStringView value);
80void writeXmlTextElement(QXmlStreamWriter *writer, QStringView name, QStringView xmlns, QStringView value);
81void writeOptionalXmlTextElement(QXmlStreamWriter *writer, QStringView name, QStringView value);
82void writeEmptyElement(QXmlStreamWriter *writer, QStringView name, QStringView xmlns);
84inline void writeOptional(QXmlStreamWriter *writer,
const std::optional<T> &value)
92std::optional<QByteArray> parseBase64(
const QString &);
93inline QString serializeBase64(
const QByteArray &data) {
return QString::fromUtf8(data.toBase64()); }
97std::optional<Int> parseInt(QStringView str);
99inline QString serializeInt(Int value) {
return QString::number(value); }
102std::optional<bool> parseBoolean(
const QString &str);
103QString serializeBoolean(
bool);
109QXMPP_EXPORT
bool isIqType(
const QDomElement &, QStringView tagName, QStringView xmlns);
110QXMPP_EXPORT QDomElement firstChildElement(
const QDomElement &, QStringView tagName = {}, QStringView xmlNs = {});
111QXMPP_EXPORT QDomElement nextSiblingElement(
const QDomElement &, QStringView tagName = {}, QStringView xmlNs = {});
113struct DomChildElements {
116 QStringView namespaceUri;
118 struct EndIterator { };
120 Iterator operator++()
122 el = nextSiblingElement(el, tagName, namespaceUri);
125 bool operator!=(EndIterator)
const {
return !el.isNull(); }
126 const QDomElement &operator*()
const {
return el; }
130 QStringView namespaceUri;
133 Iterator begin()
const {
return { firstChildElement(parent, tagName, namespaceUri), tagName, namespaceUri }; }
134 EndIterator end()
const {
return {}; }
137inline DomChildElements iterChildElements(
const QDomElement &el, QStringView tagName = {}, QStringView namespaceUri = {}) {
return DomChildElements { el, tagName, namespaceUri }; }
139std::vector<QString> parseTextElements(DomChildElements elements);
141QByteArray serializeXml(
const void *packet,
void (*toXml)(
const void *, QXmlStreamWriter *));
143inline QByteArray serializeXml(
const T &packet)
145 return serializeXml(&packet, [](
const void *packet, QXmlStreamWriter *w) {
146 std::invoke(&T::toXml,
reinterpret_cast<const T *
>(packet), w);
150QXMPP_EXPORT QByteArray generateRandomBytes(uint32_t minimumByteCount, uint32_t maximumByteCount);
151QXMPP_EXPORT
void generateRandomBytes(uint8_t *bytes, uint32_t byteCount);
152float calculateProgress(qint64 transferred, qint64 total);
154QXMPP_EXPORT std::pair<QString, int> parseHostAddress(
const QString &address);
Definition: QXmppNonza.h:14