summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@qt.io>2023-06-28 14:52:43 +0200
committerMarc Mutz <marc.mutz@qt.io>2023-07-05 12:56:55 +0200
commitaf32768f18f8fed1ce3d06a6bad5fd65d0574a3a (patch)
treeed5257b35ceedbec428de54be83ee32c9533d0dd
parente090853ad598aa4f39304d69ec29b80fc3fceb62 (diff)
QDebug: add getter/setter for noQuotes
There were setters (quote(), noquote()), but, unlike space()/nospace(), there was no getter. Add the getter, and, for symmetry, a parametrized setter, too. [ChangeLog][QtCore][QDebug] Added setQuoteStrings()/quoteStrings() to access and manipulate the quote()/noquote() state. Change-Id: I1b73138819b4d02726a6ef862c190206431ccebc Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
-rw-r--r--src/corelib/io/qdebug.cpp23
-rw-r--r--src/corelib/io/qdebug.h3
-rw-r--r--tests/auto/corelib/io/qdebug/tst_qdebug.cpp8
3 files changed, 33 insertions, 1 deletions
diff --git a/src/corelib/io/qdebug.cpp b/src/corelib/io/qdebug.cpp
index 56deeb7cf7..f8402dfeda 100644
--- a/src/corelib/io/qdebug.cpp
+++ b/src/corelib/io/qdebug.cpp
@@ -507,6 +507,29 @@ QDebug &QDebug::resetFormat()
/*!
+ \fn bool QDebug::quoteStrings() const
+ \since 6.7
+
+ Returns \c true if this QDebug instance will quote strings streamed into
+ it (which is the default).
+
+ \sa QDebugStateSaver, quote(), noquote(), setQuoteStrings()
+*/
+
+/*!
+ \fn void QDebug::setQuoteStrings(bool b)
+ \since 6.7
+
+ Enables quoting of strings streamed into this QDebug instance if \a b is
+ \c true; otherwise quoting is disabled.
+
+ The default is to quote strings.
+
+ \sa QDebugStateSaver, quote(), noquote(), quoteStrings()
+*/
+
+
+/*!
\fn QDebug &QDebug::quote()
\since 5.4
diff --git a/src/corelib/io/qdebug.h b/src/corelib/io/qdebug.h
index 7390a9c8bc..39f706b064 100644
--- a/src/corelib/io/qdebug.h
+++ b/src/corelib/io/qdebug.h
@@ -93,6 +93,9 @@ public:
bool autoInsertSpaces() const { return stream->space; }
void setAutoInsertSpaces(bool b) { stream->space = b; }
+ [[nodiscard]] bool quoteStrings() const noexcept { return !stream->noQuotes; }
+ void setQuoteStrings(bool b) { stream->noQuotes = !b; }
+
inline QDebug &quote() { stream->noQuotes = false; return *this; }
inline QDebug &noquote() { stream->noQuotes = true; return *this; }
inline QDebug &maybeQuote(char c = '"') { if (!stream->noQuotes) stream->ts << c; return *this; }
diff --git a/tests/auto/corelib/io/qdebug/tst_qdebug.cpp b/tests/auto/corelib/io/qdebug/tst_qdebug.cpp
index 37bb6aa65a..6c976e4a63 100644
--- a/tests/auto/corelib/io/qdebug/tst_qdebug.cpp
+++ b/tests/auto/corelib/io/qdebug/tst_qdebug.cpp
@@ -318,11 +318,17 @@ void tst_QDebug::debugNoQuotes() const
MessageHandlerSetter mhs(myMessageHandler);
{
QDebug d = qDebug();
+ QVERIFY(d.quoteStrings());
d << QStringLiteral("Hello");
+ QVERIFY(d.quoteStrings());
d.noquote();
+ QVERIFY(!d.quoteStrings());
d << QStringLiteral("Hello");
+ QVERIFY(!d.quoteStrings());
d.quote();
+ QVERIFY(d.quoteStrings());
d << QStringLiteral("Hello");
+ QVERIFY(d.quoteStrings());
}
QCOMPARE(s_msg, QString::fromLatin1("\"Hello\" Hello \"Hello\""));
@@ -331,7 +337,7 @@ void tst_QDebug::debugNoQuotes() const
d << QChar('H');
d << QLatin1String("Hello");
d << QByteArray("Hello");
- d.noquote();
+ d.setQuoteStrings(false);
d << QChar('H');
d << QLatin1String("Hello");
d << QByteArray("Hello");