Implement QXmlStreamReader::hasStandaloneDeclaration()

This patch implements a public getter for the hasStandalone attribute.
It returns true, if standalone has been explicitly declared in an XML
header and false otherwise.

As this is no longer necessary it removes accessing QXmlStreamPrivate
from QDomParser.

[ChangeLog][QtCore][QXmlStreamReader] added hasStandaloneDeclaration()

Change-Id: Iaaa0a728a6f7186e40637186077f7b49c112f7a9
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Reviewed-by: Yuhang Zhao <yuhangzhao@deepin.org>
This commit is contained in:
Axel Spoerl 2023-04-21 13:36:29 +02:00
parent b85a9d0ee1
commit 55a51e1909
4 changed files with 19 additions and 4 deletions

View File

@ -2692,6 +2692,8 @@ bool QXmlStreamReader::isCDATA() const
XML declaration; otherwise returns \c false.
If no XML declaration has been parsed, this function returns \c false.
\sa hasStandaloneDeclaration()
*/
bool QXmlStreamReader::isStandaloneDocument() const
{
@ -2699,6 +2701,21 @@ bool QXmlStreamReader::isStandaloneDocument() const
return d->standalone;
}
/*!
\since 6.6
Returns \c true if this document has an explicit standalone
declaration (can be 'yes' or 'no'); otherwise returns \c false;
If no XML declaration has been parsed, this function returns \c false.
\sa isStandaloneDocument()
*/
bool QXmlStreamReader::hasStandaloneDeclaration() const
{
Q_D(const QXmlStreamReader);
return d->hasStandalone;
}
/*!
\since 4.4

View File

@ -246,6 +246,7 @@ public:
inline bool isProcessingInstruction() const { return tokenType() == ProcessingInstruction; }
bool isStandaloneDocument() const;
bool hasStandaloneDeclaration() const;
QStringView documentVersion() const;
QStringView documentEncoding() const;

View File

@ -510,8 +510,6 @@ public:
QXmlStreamEntityResolver *entityResolver;
static QXmlStreamReaderPrivate *get(QXmlStreamReader *q) { return q->d_func(); }
private:
/*! \internal
Never assign to variable type directly. Instead use this function.

View File

@ -266,8 +266,7 @@ bool QDomParser::parseProlog()
value += u" standalone='yes'"_s;
} else {
// Add the standalone attribute only if it was specified
QXmlStreamReaderPrivate *priv = QXmlStreamReaderPrivate::get(reader);
if (priv->hasStandalone)
if (reader->hasStandaloneDeclaration())
value += u" standalone='no'"_s;
}