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>
This commit is contained in:
parent
e090853ad5
commit
af32768f18
@ -506,6 +506,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()
|
\fn QDebug &QDebug::quote()
|
||||||
\since 5.4
|
\since 5.4
|
||||||
|
@ -93,6 +93,9 @@ public:
|
|||||||
bool autoInsertSpaces() const { return stream->space; }
|
bool autoInsertSpaces() const { return stream->space; }
|
||||||
void setAutoInsertSpaces(bool b) { stream->space = b; }
|
void setAutoInsertSpaces(bool b) { stream->space = b; }
|
||||||
|
|
||||||
|
[[nodiscard]] bool quoteStrings() const noexcept { return !stream->noQuotes; }
|
||||||
|
void setQuoteStrings(bool b) { stream->noQuotes = !b; }
|
||||||
|
|
||||||
inline QDebug "e() { stream->noQuotes = false; return *this; }
|
inline QDebug "e() { stream->noQuotes = false; return *this; }
|
||||||
inline QDebug &noquote() { stream->noQuotes = true; return *this; }
|
inline QDebug &noquote() { stream->noQuotes = true; return *this; }
|
||||||
inline QDebug &maybeQuote(char c = '"') { if (!stream->noQuotes) stream->ts << c; return *this; }
|
inline QDebug &maybeQuote(char c = '"') { if (!stream->noQuotes) stream->ts << c; return *this; }
|
||||||
|
@ -318,11 +318,17 @@ void tst_QDebug::debugNoQuotes() const
|
|||||||
MessageHandlerSetter mhs(myMessageHandler);
|
MessageHandlerSetter mhs(myMessageHandler);
|
||||||
{
|
{
|
||||||
QDebug d = qDebug();
|
QDebug d = qDebug();
|
||||||
|
QVERIFY(d.quoteStrings());
|
||||||
d << QStringLiteral("Hello");
|
d << QStringLiteral("Hello");
|
||||||
|
QVERIFY(d.quoteStrings());
|
||||||
d.noquote();
|
d.noquote();
|
||||||
|
QVERIFY(!d.quoteStrings());
|
||||||
d << QStringLiteral("Hello");
|
d << QStringLiteral("Hello");
|
||||||
|
QVERIFY(!d.quoteStrings());
|
||||||
d.quote();
|
d.quote();
|
||||||
|
QVERIFY(d.quoteStrings());
|
||||||
d << QStringLiteral("Hello");
|
d << QStringLiteral("Hello");
|
||||||
|
QVERIFY(d.quoteStrings());
|
||||||
}
|
}
|
||||||
QCOMPARE(s_msg, QString::fromLatin1("\"Hello\" Hello \"Hello\""));
|
QCOMPARE(s_msg, QString::fromLatin1("\"Hello\" Hello \"Hello\""));
|
||||||
|
|
||||||
@ -331,7 +337,7 @@ void tst_QDebug::debugNoQuotes() const
|
|||||||
d << QChar('H');
|
d << QChar('H');
|
||||||
d << QLatin1String("Hello");
|
d << QLatin1String("Hello");
|
||||||
d << QByteArray("Hello");
|
d << QByteArray("Hello");
|
||||||
d.noquote();
|
d.setQuoteStrings(false);
|
||||||
d << QChar('H');
|
d << QChar('H');
|
||||||
d << QLatin1String("Hello");
|
d << QLatin1String("Hello");
|
||||||
d << QByteArray("Hello");
|
d << QByteArray("Hello");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user