From cd83859bd6310a2cf0a67c489aa597dc87e326b4 Mon Sep 17 00:00:00 2001 From: Kai Koehne Date: Wed, 11 Feb 2015 10:22:01 +0100 Subject: Network: Fix operator<<(QDebug, ...) operations Use the QDebugStateSaver saver(debug); debug.resetFormat().nospace(); idiom to unify the formatting and whitespace handling. Change-Id: Id346d63b3f589b60ca19e4459271d587f1a0c003 Reviewed-by: Richard J. Moore --- src/network/access/qnetworkcookie.cpp | 6 +++-- src/network/kernel/qhostaddress.cpp | 8 ++++--- src/network/kernel/qnetworkinterface.cpp | 38 +++++++++++++++++--------------- src/network/kernel/qnetworkproxy.cpp | 2 ++ src/network/socket/qabstractsocket.cpp | 4 ++++ src/network/socket/qlocalsocket.cpp | 4 ++++ src/network/ssl/qsslcertificate.cpp | 16 ++++++++------ src/network/ssl/qsslcipher.cpp | 6 +++-- src/network/ssl/qsslellipticcurve.cpp | 3 ++- src/network/ssl/qsslkey_p.cpp | 3 ++- 10 files changed, 56 insertions(+), 34 deletions(-) (limited to 'src') diff --git a/src/network/access/qnetworkcookie.cpp b/src/network/access/qnetworkcookie.cpp index 0fe1f3981c..2b11e5f993 100644 --- a/src/network/access/qnetworkcookie.cpp +++ b/src/network/access/qnetworkcookie.cpp @@ -1034,8 +1034,10 @@ void QNetworkCookie::normalize(const QUrl &url) #ifndef QT_NO_DEBUG_STREAM QDebug operator<<(QDebug s, const QNetworkCookie &cookie) { - s.nospace() << "QNetworkCookie(" << cookie.toRawForm(QNetworkCookie::Full) << ')'; - return s.space(); + QDebugStateSaver saver(s); + s.resetFormat().nospace(); + s << "QNetworkCookie(" << cookie.toRawForm(QNetworkCookie::Full) << ')'; + return s; } #endif diff --git a/src/network/kernel/qhostaddress.cpp b/src/network/kernel/qhostaddress.cpp index 75a886ddb6..2054fb2c0a 100644 --- a/src/network/kernel/qhostaddress.cpp +++ b/src/network/kernel/qhostaddress.cpp @@ -1040,11 +1040,13 @@ bool QHostAddress::isLoopback() const #ifndef QT_NO_DEBUG_STREAM QDebug operator<<(QDebug d, const QHostAddress &address) { + QDebugStateSaver saver(d); + d.resetFormat().nospace(); if (address == QHostAddress::Any) - d.maybeSpace() << "QHostAddress(QHostAddress::Any)"; + d << "QHostAddress(QHostAddress::Any)"; else - d.maybeSpace() << "QHostAddress(" << address.toString() << ')'; - return d.space(); + d << "QHostAddress(" << address.toString() << ')'; + return d; } #endif diff --git a/src/network/kernel/qnetworkinterface.cpp b/src/network/kernel/qnetworkinterface.cpp index c62244fab3..8d891733ac 100644 --- a/src/network/kernel/qnetworkinterface.cpp +++ b/src/network/kernel/qnetworkinterface.cpp @@ -580,40 +580,42 @@ QList QNetworkInterface::allAddresses() static inline QDebug flagsDebug(QDebug debug, QNetworkInterface::InterfaceFlags flags) { if (flags & QNetworkInterface::IsUp) - debug.nospace() << "IsUp "; + debug << "IsUp "; if (flags & QNetworkInterface::IsRunning) - debug.nospace() << "IsRunning "; + debug << "IsRunning "; if (flags & QNetworkInterface::CanBroadcast) - debug.nospace() << "CanBroadcast "; + debug << "CanBroadcast "; if (flags & QNetworkInterface::IsLoopBack) - debug.nospace() << "IsLoopBack "; + debug << "IsLoopBack "; if (flags & QNetworkInterface::IsPointToPoint) - debug.nospace() << "IsPointToPoint "; + debug << "IsPointToPoint "; if (flags & QNetworkInterface::CanMulticast) - debug.nospace() << "CanMulticast "; - return debug.nospace(); + debug << "CanMulticast "; + return debug; } static inline QDebug operator<<(QDebug debug, const QNetworkAddressEntry &entry) { - debug.nospace() << "(address = " << entry.ip(); + debug << "(address = " << entry.ip(); if (!entry.netmask().isNull()) - debug.nospace() << ", netmask = " << entry.netmask(); + debug << ", netmask = " << entry.netmask(); if (!entry.broadcast().isNull()) - debug.nospace() << ", broadcast = " << entry.broadcast(); - debug.nospace() << ')'; - return debug.space(); + debug << ", broadcast = " << entry.broadcast(); + debug << ')'; + return debug; } QDebug operator<<(QDebug debug, const QNetworkInterface &networkInterface) { - debug.nospace() << "QNetworkInterface(name = " << networkInterface.name() - << ", hardware address = " << networkInterface.hardwareAddress() - << ", flags = "; + QDebugStateSaver saver(debug); + debug.resetFormat().nospace(); + debug << "QNetworkInterface(name = " << networkInterface.name() + << ", hardware address = " << networkInterface.hardwareAddress() + << ", flags = "; flagsDebug(debug, networkInterface.flags()); - debug.nospace() << ", entries = " << networkInterface.addressEntries() - << ")\n"; - return debug.space(); + debug << ", entries = " << networkInterface.addressEntries() + << ")\n"; + return debug; } #endif diff --git a/src/network/kernel/qnetworkproxy.cpp b/src/network/kernel/qnetworkproxy.cpp index 53233670e6..53c4410fab 100644 --- a/src/network/kernel/qnetworkproxy.cpp +++ b/src/network/kernel/qnetworkproxy.cpp @@ -1580,6 +1580,8 @@ QList QNetworkProxyFactory::proxyForQuery(const QNetworkProxyQuer */ QDebug operator<<(QDebug debug, const QNetworkProxy &proxy) { + QDebugStateSaver saver(debug); + debug.resetFormat().nospace(); QNetworkProxy::ProxyType type = proxy.type(); switch (type) { case QNetworkProxy::NoProxy: diff --git a/src/network/socket/qabstractsocket.cpp b/src/network/socket/qabstractsocket.cpp index 76874823f0..f9fe40955a 100644 --- a/src/network/socket/qabstractsocket.cpp +++ b/src/network/socket/qabstractsocket.cpp @@ -2915,6 +2915,8 @@ QNetworkProxy QAbstractSocket::proxy() const #ifndef QT_NO_DEBUG_STREAM Q_NETWORK_EXPORT QDebug operator<<(QDebug debug, QAbstractSocket::SocketError error) { + QDebugStateSaver saver(debug); + debug.resetFormat().nospace(); switch (error) { case QAbstractSocket::ConnectionRefusedError: debug << "QAbstractSocket::ConnectionRefusedError"; @@ -2982,6 +2984,8 @@ Q_NETWORK_EXPORT QDebug operator<<(QDebug debug, QAbstractSocket::SocketError er Q_NETWORK_EXPORT QDebug operator<<(QDebug debug, QAbstractSocket::SocketState state) { + QDebugStateSaver saver(debug); + debug.resetFormat().nospace(); switch (state) { case QAbstractSocket::UnconnectedState: debug << "QAbstractSocket::UnconnectedState"; diff --git a/src/network/socket/qlocalsocket.cpp b/src/network/socket/qlocalsocket.cpp index f11972807b..990b282071 100644 --- a/src/network/socket/qlocalsocket.cpp +++ b/src/network/socket/qlocalsocket.cpp @@ -487,6 +487,8 @@ bool QLocalSocket::isSequential() const #ifndef QT_NO_DEBUG_STREAM QDebug operator<<(QDebug debug, QLocalSocket::LocalSocketError error) { + QDebugStateSaver saver(debug); + debug.resetFormat().nospace(); switch (error) { case QLocalSocket::ConnectionRefusedError: debug << "QLocalSocket::ConnectionRefusedError"; @@ -527,6 +529,8 @@ QDebug operator<<(QDebug debug, QLocalSocket::LocalSocketError error) QDebug operator<<(QDebug debug, QLocalSocket::LocalSocketState state) { + QDebugStateSaver saver(debug); + debug.resetFormat().nospace(); switch (state) { case QLocalSocket::UnconnectedState: debug << "QLocalSocket::UnconnectedState"; diff --git a/src/network/ssl/qsslcertificate.cpp b/src/network/ssl/qsslcertificate.cpp index 01951bef08..1aac152ca3 100644 --- a/src/network/ssl/qsslcertificate.cpp +++ b/src/network/ssl/qsslcertificate.cpp @@ -682,16 +682,18 @@ QByteArray QSslCertificatePrivate::subjectInfoToString(QSslCertificate::SubjectI #ifndef QT_NO_DEBUG_STREAM QDebug operator<<(QDebug debug, const QSslCertificate &certificate) { + QDebugStateSaver saver(debug); + debug.resetFormat().nospace(); debug << "QSslCertificate(" << certificate.version() - << ',' << certificate.serialNumber() - << ',' << certificate.digest().toBase64() - << ',' << certificate.issuerInfo(QSslCertificate::Organization) - << ',' << certificate.subjectInfo(QSslCertificate::Organization) - << ',' << certificate.subjectAlternativeNames() + << ", " << certificate.serialNumber() + << ", " << certificate.digest().toBase64() + << ", " << certificate.issuerInfo(QSslCertificate::Organization) + << ", " << certificate.subjectInfo(QSslCertificate::Organization) + << ", " << certificate.subjectAlternativeNames() #ifndef QT_NO_DATESTRING - << ',' << certificate.effectiveDate() - << ',' << certificate.expiryDate() + << ", " << certificate.effectiveDate() + << ", " << certificate.expiryDate() #endif << ')'; return debug; diff --git a/src/network/ssl/qsslcipher.cpp b/src/network/ssl/qsslcipher.cpp index f60569942f..8f2b8b54ad 100644 --- a/src/network/ssl/qsslcipher.cpp +++ b/src/network/ssl/qsslcipher.cpp @@ -248,9 +248,11 @@ QSsl::SslProtocol QSslCipher::protocol() const #ifndef QT_NO_DEBUG_STREAM QDebug operator<<(QDebug debug, const QSslCipher &cipher) { - debug << "QSslCipher(name=" << qPrintable(cipher.name()) + QDebugStateSaver saver(debug); + debug.resetFormat().nospace().noquote(); + debug << "QSslCipher(name=" << cipher.name() << ", bits=" << cipher.usedBits() - << ", proto=" << qPrintable(cipher.protocolString()) + << ", proto=" << cipher.protocolString() << ')'; return debug; } diff --git a/src/network/ssl/qsslellipticcurve.cpp b/src/network/ssl/qsslellipticcurve.cpp index 31b8b8f57e..a16f726429 100644 --- a/src/network/ssl/qsslellipticcurve.cpp +++ b/src/network/ssl/qsslellipticcurve.cpp @@ -170,7 +170,8 @@ QT_BEGIN_NAMESPACE QDebug operator<<(QDebug debug, QSslEllipticCurve curve) { QDebugStateSaver saver(debug); - debug.nospace() << "QSslEllipticCurve(" << curve.shortName() << ")"; + debug.resetFormat().nospace(); + debug << "QSslEllipticCurve(" << curve.shortName() << ")"; return debug; } #endif diff --git a/src/network/ssl/qsslkey_p.cpp b/src/network/ssl/qsslkey_p.cpp index c18e713ef6..55a2ab7108 100644 --- a/src/network/ssl/qsslkey_p.cpp +++ b/src/network/ssl/qsslkey_p.cpp @@ -444,9 +444,10 @@ bool QSslKey::operator==(const QSslKey &other) const */ #ifndef QT_NO_DEBUG_STREAM -class QDebug; QDebug operator<<(QDebug debug, const QSslKey &key) { + QDebugStateSaver saver(debug); + debug.resetFormat().nospace(); debug << "QSslKey(" << (key.type() == QSsl::PublicKey ? "PublicKey" : "PrivateKey") << ", " << (key.algorithm() == QSsl::Opaque ? "OPAQUE" : -- cgit v1.2.3