| 1 | /**************************************************************************** |
| 2 | ** |
| 3 | ** Copyright (C) 2020 The Qt Company Ltd. |
| 4 | ** Copyright (C) 2016 Intel Corporation. |
| 5 | ** Contact: https://www.qt.io/licensing/ |
| 6 | ** |
| 7 | ** This file is part of the QtCore module of the Qt Toolkit. |
| 8 | ** |
| 9 | ** $QT_BEGIN_LICENSE:LGPL$ |
| 10 | ** Commercial License Usage |
| 11 | ** Licensees holding valid commercial Qt licenses may use this file in |
| 12 | ** accordance with the commercial license agreement provided with the |
| 13 | ** Software or, alternatively, in accordance with the terms contained in |
| 14 | ** a written agreement between you and The Qt Company. For licensing terms |
| 15 | ** and conditions see https://www.qt.io/terms-conditions. For further |
| 16 | ** information use the contact form at https://www.qt.io/contact-us. |
| 17 | ** |
| 18 | ** GNU Lesser General Public License Usage |
| 19 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
| 20 | ** General Public License version 3 as published by the Free Software |
| 21 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the |
| 22 | ** packaging of this file. Please review the following information to |
| 23 | ** ensure the GNU Lesser General Public License version 3 requirements |
| 24 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
| 25 | ** |
| 26 | ** GNU General Public License Usage |
| 27 | ** Alternatively, this file may be used under the terms of the GNU |
| 28 | ** General Public License version 2.0 or (at your option) the GNU General |
| 29 | ** Public license version 3 or any later version approved by the KDE Free |
| 30 | ** Qt Foundation. The licenses are as published by the Free Software |
| 31 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
| 32 | ** included in the packaging of this file. Please review the following |
| 33 | ** information to ensure the GNU General Public License requirements will |
| 34 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
| 35 | ** https://www.gnu.org/licenses/gpl-3.0.html. |
| 36 | ** |
| 37 | ** $QT_END_LICENSE$ |
| 38 | ** |
| 39 | ****************************************************************************/ |
| 40 | |
| 41 | #ifndef QURLQUERY_H |
| 42 | #define QURLQUERY_H |
| 43 | |
| 44 | #include <QtCore/qpair.h> |
| 45 | #include <QtCore/qshareddata.h> |
| 46 | #include <QtCore/qurl.h> |
| 47 | |
| 48 | #include <initializer_list> |
| 49 | |
| 50 | QT_BEGIN_NAMESPACE |
| 51 | |
| 52 | Q_CORE_EXPORT size_t qHash(const QUrlQuery &key, size_t seed = 0) noexcept; |
| 53 | |
| 54 | class QUrlQueryPrivate; |
| 55 | class Q_CORE_EXPORT QUrlQuery |
| 56 | { |
| 57 | public: |
| 58 | QUrlQuery(); |
| 59 | explicit QUrlQuery(const QUrl &url); |
| 60 | explicit QUrlQuery(const QString &queryString); |
| 61 | QUrlQuery(std::initializer_list<QPair<QString, QString>> list) |
| 62 | : QUrlQuery() |
| 63 | { |
| 64 | for (const QPair<QString, QString> &item : list) |
| 65 | addQueryItem(item.first, item.second); |
| 66 | } |
| 67 | |
| 68 | QUrlQuery(const QUrlQuery &other); |
| 69 | QUrlQuery &operator=(const QUrlQuery &other); |
| 70 | QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QUrlQuery) |
| 71 | ~QUrlQuery(); |
| 72 | |
| 73 | bool operator==(const QUrlQuery &other) const; |
| 74 | bool operator!=(const QUrlQuery &other) const |
| 75 | { return !(*this == other); } |
| 76 | |
| 77 | void swap(QUrlQuery &other) noexcept { qSwap(d, other.d); } |
| 78 | |
| 79 | bool isEmpty() const; |
| 80 | bool isDetached() const; |
| 81 | void clear(); |
| 82 | |
| 83 | QString query(QUrl::ComponentFormattingOptions encoding = QUrl::PrettyDecoded) const; |
| 84 | void setQuery(const QString &queryString); |
| 85 | QString toString(QUrl::ComponentFormattingOptions encoding = QUrl::PrettyDecoded) const |
| 86 | { return query(encoding); } |
| 87 | |
| 88 | void setQueryDelimiters(QChar valueDelimiter, QChar pairDelimiter); |
| 89 | QChar queryValueDelimiter() const; |
| 90 | QChar queryPairDelimiter() const; |
| 91 | |
| 92 | void setQueryItems(const QList<QPair<QString, QString> > &query); |
| 93 | QList<QPair<QString, QString> > queryItems(QUrl::ComponentFormattingOptions encoding = QUrl::PrettyDecoded) const; |
| 94 | |
| 95 | bool hasQueryItem(const QString &key) const; |
| 96 | void addQueryItem(const QString &key, const QString &value); |
| 97 | void removeQueryItem(const QString &key); |
| 98 | QString queryItemValue(const QString &key, QUrl::ComponentFormattingOptions encoding = QUrl::PrettyDecoded) const; |
| 99 | QStringList allQueryItemValues(const QString &key, QUrl::ComponentFormattingOptions encoding = QUrl::PrettyDecoded) const; |
| 100 | void removeAllQueryItems(const QString &key); |
| 101 | |
| 102 | static constexpr char16_t defaultQueryValueDelimiter() noexcept { return u'='; } |
| 103 | static constexpr char16_t defaultQueryPairDelimiter() noexcept { return u'&'; } |
| 104 | |
| 105 | private: |
| 106 | friend class QUrl; |
| 107 | friend Q_CORE_EXPORT size_t qHash(const QUrlQuery &key, size_t seed) noexcept; |
| 108 | QSharedDataPointer<QUrlQueryPrivate> d; |
| 109 | |
| 110 | public: |
| 111 | typedef QSharedDataPointer<QUrlQueryPrivate> DataPtr; |
| 112 | inline DataPtr &data_ptr() { return d; } |
| 113 | }; |
| 114 | |
| 115 | Q_DECLARE_SHARED(QUrlQuery) |
| 116 | |
| 117 | QT_END_NAMESPACE |
| 118 | |
| 119 | #endif // QURLQUERY_H |
| 120 | |