summaryrefslogtreecommitdiffstats
path: root/src/corelib/io/qurlquery.h
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2011-09-03 15:05:56 +0200
committerQt by Nokia <qt-info@nokia.com>2012-03-30 01:19:59 +0200
commit1aeb18038661d8da6d37fa278e37e315e35c5c42 (patch)
treea0d84714d56e45c42e6cdd0fde686ba18e91de4a /src/corelib/io/qurlquery.h
parentb75aa795feb476111a0706c52a8ebea8dff7640d (diff)
Long live QUrlQuery
This class is meant to replace the QUrl functionality that handled key-value pairs in the query part of an URL. We therefore split the URL parsing code from the code dealing with the pairs: QUrl now only needs to deal with one encoded string, without knowing what it is. Since it doesn't know how to decode the query, QUrl also becomes limited in what it can decode. Following the letter of the RFC, queries will not encode "gen-delims" nor "sub-delims" nor the plus sign (+), thus allowing the most common delimiters options to remain unchanged. QUrlQuery has some undefined behaviour when it comes to empty query keys. It may drop them or keep them; it may merge them, etc. Change-Id: Ia61096fe5060b486196ffb8532e7494eff58fec1 Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
Diffstat (limited to 'src/corelib/io/qurlquery.h')
-rw-r--r--src/corelib/io/qurlquery.h117
1 files changed, 117 insertions, 0 deletions
diff --git a/src/corelib/io/qurlquery.h b/src/corelib/io/qurlquery.h
new file mode 100644
index 0000000000..e2b28f78e7
--- /dev/null
+++ b/src/corelib/io/qurlquery.h
@@ -0,0 +1,117 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Intel Corporation
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QURLQUERY_H
+#define QURLQUERY_H
+
+#include <QtCore/qpair.h>
+#include <QtCore/qshareddata.h>
+#include <QtCore/qurl.h>
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+class QUrlQueryPrivate;
+class Q_CORE_EXPORT QUrlQuery
+{
+public:
+ QUrlQuery();
+ explicit QUrlQuery(const QUrl &url);
+ explicit QUrlQuery(const QString &queryString);
+ QUrlQuery(const QUrlQuery &other);
+ QUrlQuery &operator=(const QUrlQuery &other);
+#ifdef Q_COMPILER_RVALUE_REFS
+ QUrlQuery &operator=(QUrlQuery &&other)
+ { qSwap(d, other.d); return *this; }
+#endif
+ ~QUrlQuery();
+
+ bool operator==(const QUrlQuery &other) const;
+ bool operator!=(const QUrlQuery &other) const
+ { return !(*this == other); }
+
+ void swap(QUrlQuery &other) { qSwap(d, other.d); }
+
+ bool isEmpty() const;
+ bool isDetached() const;
+ void clear();
+
+ QString query(QUrl::ComponentFormattingOptions encoding = QUrl::PrettyDecoded) const;
+ void setQuery(const QString &queryString);
+ QString toString(QUrl::ComponentFormattingOptions encoding = QUrl::PrettyDecoded) const
+ { return query(encoding); }
+
+ void setQueryDelimiters(QChar valueDelimiter, QChar pairDelimiter);
+ QChar queryValueDelimiter() const;
+ QChar queryPairDelimiter() const;
+
+ void setQueryItems(const QList<QPair<QString, QString> > &query);
+ QList<QPair<QString, QString> > queryItems(QUrl::ComponentFormattingOptions encoding = QUrl::PrettyDecoded) const;
+
+ bool hasQueryItem(const QString &key) const;
+ void addQueryItem(const QString &key, const QString &value);
+ void removeQueryItem(const QString &key);
+ QString queryItemValue(const QString &key, QUrl::ComponentFormattingOptions encoding = QUrl::PrettyDecoded) const;
+ QStringList allQueryItemValues(const QString &key, QUrl::ComponentFormattingOptions encoding = QUrl::PrettyDecoded) const;
+ void removeAllQueryItems(const QString &key);
+
+ static QChar defaultQueryValueDelimiter()
+ { return QChar(ushort('=')); }
+ static QChar defaultQueryPairDelimiter()
+ { return QChar(ushort('&')); }
+
+private:
+ friend class QUrl;
+ QSharedDataPointer<QUrlQueryPrivate> d;
+public:
+ typedef QSharedDataPointer<QUrlQueryPrivate> DataPtr;
+ inline DataPtr &data_ptr() { return d; }
+};
+
+Q_DECLARE_TYPEINFO(QUrlQuery, Q_MOVABLE_TYPE);
+Q_DECLARE_SHARED(QUrlQuery)
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif // QURLQUERY_H