diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2019-05-27 11:35:17 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2019-05-27 12:27:29 +0200 |
commit | 54ffd0d0a3bf2c77d53e1cdfe04b362f59682cb4 (patch) | |
tree | 0e1bfe627a914b52b1663f29062981d94e8fec3e /src/websockets | |
parent | cad047230d513a33f487280aff72ef434b9d6332 (diff) | |
download | qtwebsockets-54ffd0d0a3bf2c77d53e1cdfe04b362f59682cb4.tar.gz |
Fix deprecation warnings in QWebSocketHandshakeResponse::getHandshakeResponse()
Fix warnings:
websockethandshakeresponse.cpp:151:46: warning: ‘QSet<T> QList<T>::toSet() const [with T = QString]’ is deprecated: Use QSet<T>(list.begin(), list.end()) instead. [-Wdeprecated-declarations]
qwebsockethandshakeresponse.cpp:151:84: warning: ‘QSet<T> QList<T>::toSet() const [with T = QString]’ is deprecated: Use QSet<T>(list.begin(), list.end()) instead. [-Wdeprecated-declarations]
qwebsockethandshakeresponse.cpp:151:94: warning: ‘QList<T> QSet<T>::toList() const [with T = QString]’ is deprecated: Use values() instead. [-Wdeprecated-declarations]
qwebsockethandshakeresponse.cpp:155:47: warning: ‘QSet<T> QList<T>::toSet() const [with T = QString]’ is deprecated: Use QSet<T>(list.begin(), list.end()) instead. [-Wdeprecated-declarations]
qwebsockethandshakeresponse.cpp:155:86: warning: ‘QSet<T> QList<T>::toSet() const [with T = QString]’ is deprecated: Use QSet<T>(list.begin(), list.end()) instead. [-Wdeprecated-declarations]
qwebsockethandshakeresponse.cpp:155:96: warning: ‘QList<T> QSet<T>::toList() const [with T = QString]’ is deprecated: Use values() instead. [-Wdeprecated-declarations]
qwebsockethandshakeresponse.cpp:157:46: warning: ‘QSet<T> QList<T>::toSet() const [with T = QWebSocketProtocol::Version]’ is deprecated: Use QSet<T>(list.begin(), list.end()) instead. [-Wdeprecated-declarations]
qwebsockethandshakeresponse.cpp:157:82: warning: ‘QSet<T> QList<T>::toSet() const [with T = QWebSocketProtocol::Version]’ is deprecated: Use QSet<T>(list.begin(), list.end()) instead. [-Wdeprecated-declarations]
qwebsockethandshakeresponse.cpp:157:92: warning: ‘QList<T> QSet<T>::toList() const [with T = QWebSocketProtocol::Version]’ is deprecated: Use values() instead. [-Wdeprecated-declarations]
by replacing them with a helper function to created a list intersection.
Change-Id: Iee37632517760133ceebae4eda394170293f25c3
Reviewed-by: Christian Ehrlicher <ch.ehrlicher@gmx.de>
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/websockets')
-rw-r--r-- | src/websockets/qwebsockethandshakeresponse.cpp | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/src/websockets/qwebsockethandshakeresponse.cpp b/src/websockets/qwebsockethandshakeresponse.cpp index 2241ca2..383f1bf 100644 --- a/src/websockets/qwebsockethandshakeresponse.cpp +++ b/src/websockets/qwebsockethandshakeresponse.cpp @@ -53,7 +53,9 @@ #include <QtCore/QList> #include <QtCore/QStringBuilder> //for more efficient string concatenation +#include <algorithm> #include <functional> //for std::greater +#include <iterator> QT_BEGIN_NAMESPACE @@ -124,6 +126,18 @@ QString QWebSocketHandshakeResponse::calculateAcceptKey(const QString &key) cons return QString::fromLatin1(hash.toBase64()); } +template <class T, class Compare> +static QList<T> listIntersection(QList<T> list1, QList<T> list2, Compare comp) +{ + QList<T> result; + std::sort(list1.begin(), list1.end(), comp); + std::sort(list2.begin(), list2.end(), comp); + std::set_intersection(list1.cbegin(), list1.cend(), + list2.cbegin(), list2.cend(), + std::back_inserter(result), comp); + return result; +} + /*! \internal */ @@ -148,15 +162,13 @@ QString QWebSocketHandshakeResponse::getHandshakeResponse( if (request.isValid()) { const QString acceptKey = calculateAcceptKey(request.key()); const QList<QString> matchingProtocols = - supportedProtocols.toSet().intersect(request.protocols().toSet()).toList(); + listIntersection(supportedProtocols, request.protocols(), std::less<>()); //TODO: extensions must be kept in the order in which they arrive //cannot use set.intersect() to get the supported extensions const QList<QString> matchingExtensions = - supportedExtensions.toSet().intersect(request.extensions().toSet()).toList(); - QList<QWebSocketProtocol::Version> matchingVersions = - request.versions().toSet().intersect(supportedVersions.toSet()).toList(); - std::sort(matchingVersions.begin(), matchingVersions.end(), - std::greater<QWebSocketProtocol::Version>()); //sort in descending order + listIntersection(supportedExtensions, request.extensions(), std::less<>()); + const QList<QWebSocketProtocol::Version> matchingVersions = + listIntersection(supportedVersions, request.versions(), std::greater<>()); //sort in descending order if (Q_UNLIKELY(matchingVersions.isEmpty())) { m_error = QWebSocketProtocol::CloseCodeProtocolError; |