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 <rich@kde.org>
This commit is contained in:
Kai Koehne 2015-02-11 10:22:01 +01:00
parent 7997e56a2e
commit cd83859bd6
10 changed files with 56 additions and 34 deletions

View File

@ -1034,8 +1034,10 @@ void QNetworkCookie::normalize(const QUrl &url)
#ifndef QT_NO_DEBUG_STREAM #ifndef QT_NO_DEBUG_STREAM
QDebug operator<<(QDebug s, const QNetworkCookie &cookie) QDebug operator<<(QDebug s, const QNetworkCookie &cookie)
{ {
s.nospace() << "QNetworkCookie(" << cookie.toRawForm(QNetworkCookie::Full) << ')'; QDebugStateSaver saver(s);
return s.space(); s.resetFormat().nospace();
s << "QNetworkCookie(" << cookie.toRawForm(QNetworkCookie::Full) << ')';
return s;
} }
#endif #endif

View File

@ -1040,11 +1040,13 @@ bool QHostAddress::isLoopback() const
#ifndef QT_NO_DEBUG_STREAM #ifndef QT_NO_DEBUG_STREAM
QDebug operator<<(QDebug d, const QHostAddress &address) QDebug operator<<(QDebug d, const QHostAddress &address)
{ {
QDebugStateSaver saver(d);
d.resetFormat().nospace();
if (address == QHostAddress::Any) if (address == QHostAddress::Any)
d.maybeSpace() << "QHostAddress(QHostAddress::Any)"; d << "QHostAddress(QHostAddress::Any)";
else else
d.maybeSpace() << "QHostAddress(" << address.toString() << ')'; d << "QHostAddress(" << address.toString() << ')';
return d.space(); return d;
} }
#endif #endif

View File

@ -580,40 +580,42 @@ QList<QHostAddress> QNetworkInterface::allAddresses()
static inline QDebug flagsDebug(QDebug debug, QNetworkInterface::InterfaceFlags flags) static inline QDebug flagsDebug(QDebug debug, QNetworkInterface::InterfaceFlags flags)
{ {
if (flags & QNetworkInterface::IsUp) if (flags & QNetworkInterface::IsUp)
debug.nospace() << "IsUp "; debug << "IsUp ";
if (flags & QNetworkInterface::IsRunning) if (flags & QNetworkInterface::IsRunning)
debug.nospace() << "IsRunning "; debug << "IsRunning ";
if (flags & QNetworkInterface::CanBroadcast) if (flags & QNetworkInterface::CanBroadcast)
debug.nospace() << "CanBroadcast "; debug << "CanBroadcast ";
if (flags & QNetworkInterface::IsLoopBack) if (flags & QNetworkInterface::IsLoopBack)
debug.nospace() << "IsLoopBack "; debug << "IsLoopBack ";
if (flags & QNetworkInterface::IsPointToPoint) if (flags & QNetworkInterface::IsPointToPoint)
debug.nospace() << "IsPointToPoint "; debug << "IsPointToPoint ";
if (flags & QNetworkInterface::CanMulticast) if (flags & QNetworkInterface::CanMulticast)
debug.nospace() << "CanMulticast "; debug << "CanMulticast ";
return debug.nospace(); return debug;
} }
static inline QDebug operator<<(QDebug debug, const QNetworkAddressEntry &entry) static inline QDebug operator<<(QDebug debug, const QNetworkAddressEntry &entry)
{ {
debug.nospace() << "(address = " << entry.ip(); debug << "(address = " << entry.ip();
if (!entry.netmask().isNull()) if (!entry.netmask().isNull())
debug.nospace() << ", netmask = " << entry.netmask(); debug << ", netmask = " << entry.netmask();
if (!entry.broadcast().isNull()) if (!entry.broadcast().isNull())
debug.nospace() << ", broadcast = " << entry.broadcast(); debug << ", broadcast = " << entry.broadcast();
debug.nospace() << ')'; debug << ')';
return debug.space(); return debug;
} }
QDebug operator<<(QDebug debug, const QNetworkInterface &networkInterface) QDebug operator<<(QDebug debug, const QNetworkInterface &networkInterface)
{ {
debug.nospace() << "QNetworkInterface(name = " << networkInterface.name() QDebugStateSaver saver(debug);
debug.resetFormat().nospace();
debug << "QNetworkInterface(name = " << networkInterface.name()
<< ", hardware address = " << networkInterface.hardwareAddress() << ", hardware address = " << networkInterface.hardwareAddress()
<< ", flags = "; << ", flags = ";
flagsDebug(debug, networkInterface.flags()); flagsDebug(debug, networkInterface.flags());
debug.nospace() << ", entries = " << networkInterface.addressEntries() debug << ", entries = " << networkInterface.addressEntries()
<< ")\n"; << ")\n";
return debug.space(); return debug;
} }
#endif #endif

View File

@ -1580,6 +1580,8 @@ QList<QNetworkProxy> QNetworkProxyFactory::proxyForQuery(const QNetworkProxyQuer
*/ */
QDebug operator<<(QDebug debug, const QNetworkProxy &proxy) QDebug operator<<(QDebug debug, const QNetworkProxy &proxy)
{ {
QDebugStateSaver saver(debug);
debug.resetFormat().nospace();
QNetworkProxy::ProxyType type = proxy.type(); QNetworkProxy::ProxyType type = proxy.type();
switch (type) { switch (type) {
case QNetworkProxy::NoProxy: case QNetworkProxy::NoProxy:

View File

@ -2915,6 +2915,8 @@ QNetworkProxy QAbstractSocket::proxy() const
#ifndef QT_NO_DEBUG_STREAM #ifndef QT_NO_DEBUG_STREAM
Q_NETWORK_EXPORT QDebug operator<<(QDebug debug, QAbstractSocket::SocketError error) Q_NETWORK_EXPORT QDebug operator<<(QDebug debug, QAbstractSocket::SocketError error)
{ {
QDebugStateSaver saver(debug);
debug.resetFormat().nospace();
switch (error) { switch (error) {
case QAbstractSocket::ConnectionRefusedError: case QAbstractSocket::ConnectionRefusedError:
debug << "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) Q_NETWORK_EXPORT QDebug operator<<(QDebug debug, QAbstractSocket::SocketState state)
{ {
QDebugStateSaver saver(debug);
debug.resetFormat().nospace();
switch (state) { switch (state) {
case QAbstractSocket::UnconnectedState: case QAbstractSocket::UnconnectedState:
debug << "QAbstractSocket::UnconnectedState"; debug << "QAbstractSocket::UnconnectedState";

View File

@ -487,6 +487,8 @@ bool QLocalSocket::isSequential() const
#ifndef QT_NO_DEBUG_STREAM #ifndef QT_NO_DEBUG_STREAM
QDebug operator<<(QDebug debug, QLocalSocket::LocalSocketError error) QDebug operator<<(QDebug debug, QLocalSocket::LocalSocketError error)
{ {
QDebugStateSaver saver(debug);
debug.resetFormat().nospace();
switch (error) { switch (error) {
case QLocalSocket::ConnectionRefusedError: case QLocalSocket::ConnectionRefusedError:
debug << "QLocalSocket::ConnectionRefusedError"; debug << "QLocalSocket::ConnectionRefusedError";
@ -527,6 +529,8 @@ QDebug operator<<(QDebug debug, QLocalSocket::LocalSocketError error)
QDebug operator<<(QDebug debug, QLocalSocket::LocalSocketState state) QDebug operator<<(QDebug debug, QLocalSocket::LocalSocketState state)
{ {
QDebugStateSaver saver(debug);
debug.resetFormat().nospace();
switch (state) { switch (state) {
case QLocalSocket::UnconnectedState: case QLocalSocket::UnconnectedState:
debug << "QLocalSocket::UnconnectedState"; debug << "QLocalSocket::UnconnectedState";

View File

@ -682,16 +682,18 @@ QByteArray QSslCertificatePrivate::subjectInfoToString(QSslCertificate::SubjectI
#ifndef QT_NO_DEBUG_STREAM #ifndef QT_NO_DEBUG_STREAM
QDebug operator<<(QDebug debug, const QSslCertificate &certificate) QDebug operator<<(QDebug debug, const QSslCertificate &certificate)
{ {
QDebugStateSaver saver(debug);
debug.resetFormat().nospace();
debug << "QSslCertificate(" debug << "QSslCertificate("
<< certificate.version() << certificate.version()
<< ',' << certificate.serialNumber() << ", " << certificate.serialNumber()
<< ',' << certificate.digest().toBase64() << ", " << certificate.digest().toBase64()
<< ',' << certificate.issuerInfo(QSslCertificate::Organization) << ", " << certificate.issuerInfo(QSslCertificate::Organization)
<< ',' << certificate.subjectInfo(QSslCertificate::Organization) << ", " << certificate.subjectInfo(QSslCertificate::Organization)
<< ',' << certificate.subjectAlternativeNames() << ", " << certificate.subjectAlternativeNames()
#ifndef QT_NO_DATESTRING #ifndef QT_NO_DATESTRING
<< ',' << certificate.effectiveDate() << ", " << certificate.effectiveDate()
<< ',' << certificate.expiryDate() << ", " << certificate.expiryDate()
#endif #endif
<< ')'; << ')';
return debug; return debug;

View File

@ -248,9 +248,11 @@ QSsl::SslProtocol QSslCipher::protocol() const
#ifndef QT_NO_DEBUG_STREAM #ifndef QT_NO_DEBUG_STREAM
QDebug operator<<(QDebug debug, const QSslCipher &cipher) 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() << ", bits=" << cipher.usedBits()
<< ", proto=" << qPrintable(cipher.protocolString()) << ", proto=" << cipher.protocolString()
<< ')'; << ')';
return debug; return debug;
} }

View File

@ -170,7 +170,8 @@ QT_BEGIN_NAMESPACE
QDebug operator<<(QDebug debug, QSslEllipticCurve curve) QDebug operator<<(QDebug debug, QSslEllipticCurve curve)
{ {
QDebugStateSaver saver(debug); QDebugStateSaver saver(debug);
debug.nospace() << "QSslEllipticCurve(" << curve.shortName() << ")"; debug.resetFormat().nospace();
debug << "QSslEllipticCurve(" << curve.shortName() << ")";
return debug; return debug;
} }
#endif #endif

View File

@ -444,9 +444,10 @@ bool QSslKey::operator==(const QSslKey &other) const
*/ */
#ifndef QT_NO_DEBUG_STREAM #ifndef QT_NO_DEBUG_STREAM
class QDebug;
QDebug operator<<(QDebug debug, const QSslKey &key) QDebug operator<<(QDebug debug, const QSslKey &key)
{ {
QDebugStateSaver saver(debug);
debug.resetFormat().nospace();
debug << "QSslKey(" debug << "QSslKey("
<< (key.type() == QSsl::PublicKey ? "PublicKey" : "PrivateKey") << (key.type() == QSsl::PublicKey ? "PublicKey" : "PrivateKey")
<< ", " << (key.algorithm() == QSsl::Opaque ? "OPAQUE" : << ", " << (key.algorithm() == QSsl::Opaque ? "OPAQUE" :