Kgapi

utils.h
1/*
2 * This file is part of LibKGAPI library
3 *
4 * SPDX-FileCopyrightText: 2013 Daniel Vrátil <dvratil@redhat.com>
5 *
6 * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
7 */
8
9#pragma once
10
11#include <QString>
12
13#include "kgapicore_export.h"
14#include "types.h"
15
16namespace Utils
17{
18
19/**
20 * @brief Converts string content type into enum.
21 *
22 * @param contentType Content type in form of "text/plain" or "application/xml"
23 * @return Corresponding enum member or KGAPI2::UnknownContentType
24 *
25 * @since 2.0
26 */
27KGAPICORE_EXPORT KGAPI2::ContentType stringToContentType(const QString &contentType);
28
29/**
30 * @brief Converts given boolean value to strings "true" or "false".
31 *
32 * @param val
33 */
34KGAPICORE_EXPORT QString bool2Str(bool val);
35
36/**
37 * @brief Converts given timestamp into RFC3339 date string
38 *
39 * @param timestamp
40 */
41KGAPICORE_EXPORT QString ts2Str(quint64 timestamp);
42
43/**
44 * @brief Converts given string in RFC3339 format into QDateTime
45 */
46KGAPICORE_EXPORT QDateTime rfc3339DateFromString(const QString &string);
47
48/**
49 * @brief Converts given date time to RFC3339 format
50 */
51KGAPICORE_EXPORT QString rfc3339DateToString(const QDateTime &dt);
52
53template<typename Value, template<typename> class Container>
54bool compareSharedPtrContainers(const Container<QSharedPointer<Value>> &left, const Container<QSharedPointer<Value>> &right)
55{
56 if (left.size() != right.size()) {
57 return false;
58 }
59 auto it1 = left.cbegin(), it2 = right.cbegin();
60 const auto end1 = left.cend();
61 for (; it1 != end1; ++it1, ++it2) {
62 if ((*it1 == nullptr) != (*it2 == nullptr)) {
63 return false;
64 }
65 if (!*it1 && !*it2) {
66 continue;
67 }
68 if (**it1 != **it2) {
69 return false;
70 }
71 }
72 return true;
73}
74} // namespace Utils
ContentType
Definition types.h:210
QTextStream & left(QTextStream &stream)
QTextStream & right(QTextStream &stream)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:19:51 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.