File indexing completed on 2024-05-12 05:22:15
0001 /* 0002 * This file is part of LibKGAPI library 0003 * 0004 * SPDX-FileCopyrightText: 2013 Daniel Vrátil <dvratil@redhat.com> 0005 * 0006 * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0007 */ 0008 0009 #pragma once 0010 0011 #include <QString> 0012 0013 #include "kgapicore_export.h" 0014 #include "types.h" 0015 0016 namespace Utils 0017 { 0018 0019 /** 0020 * @brief Converts string content type into enum. 0021 * 0022 * @param contentType Content type in form of "text/plain" or "application/xml" 0023 * @return Corresponding enum member or KGAPI2::UnknownContentType 0024 * 0025 * @since 2.0 0026 */ 0027 KGAPICORE_EXPORT KGAPI2::ContentType stringToContentType(const QString &contentType); 0028 0029 /** 0030 * @brief Converts given boolean value to strings "true" or "false". 0031 * 0032 * @param val 0033 */ 0034 KGAPICORE_EXPORT QString bool2Str(bool val); 0035 0036 /** 0037 * @brief Converts given timestamp into RFC3339 date string 0038 * 0039 * @param timestamp 0040 */ 0041 KGAPICORE_EXPORT QString ts2Str(quint64 timestamp); 0042 0043 /** 0044 * @brief Converts given string in RFC3339 format into QDateTime 0045 */ 0046 KGAPICORE_EXPORT QDateTime rfc3339DateFromString(const QString &string); 0047 0048 /** 0049 * @brief Converts given date time to RFC3339 format 0050 */ 0051 KGAPICORE_EXPORT QString rfc3339DateToString(const QDateTime &dt); 0052 0053 template<typename Value, template<typename> class Container> 0054 bool compareSharedPtrContainers(const Container<QSharedPointer<Value>> &left, const Container<QSharedPointer<Value>> &right) 0055 { 0056 if (left.size() != right.size()) { 0057 return false; 0058 } 0059 auto it1 = left.cbegin(), it2 = right.cbegin(); 0060 const auto end1 = left.cend(); 0061 for (; it1 != end1; ++it1, ++it2) { 0062 if ((*it1 == nullptr) != (*it2 == nullptr)) { 0063 return false; 0064 } 0065 if (!*it1 && !*it2) { 0066 continue; 0067 } 0068 if (**it1 != **it2) { 0069 return false; 0070 } 0071 } 0072 return true; 0073 } 0074 } // namespace Utils