Port the QXmlStream API from QStringRef to QStringView

This gives some source incompatibilities, most of them can be
handled by using auto instead of QStringRef explicitly.

[ChangeLog][Important API changes] QXmlStream now uses QStringView
insteead of QStringRef in it's API. Using auto forvariables returning
a QStringRef in Qt 5 should lead to code that can be used against both
Qt versions.

Fixes: QTBUG-84317
Change-Id: I6df3a9507276f5d16d044a6bdbe0e4810cf99440
Reviewed-by: Maurice Kalinowski <maurice.kalinowski@qt.io>
This commit is contained in:
Karsten Heimrich 2020-08-12 11:58:54 +02:00
parent a2cec17407
commit a8028a02df
13 changed files with 138 additions and 150 deletions

View File

@ -195,7 +195,7 @@ static QVariant mapFromXml(QXmlStreamReader &xml, Converter::Options options)
static QVariant variantFromXml(QXmlStreamReader &xml, Converter::Options options) static QVariant variantFromXml(QXmlStreamReader &xml, Converter::Options options)
{ {
QStringRef name = xml.name(); QStringView name = xml.name();
if (name == QLatin1String("list")) if (name == QLatin1String("list"))
return listFromXml(xml, options); return listFromXml(xml, options);
if (name == QLatin1String("map")) if (name == QLatin1String("map"))
@ -207,7 +207,7 @@ static QVariant variantFromXml(QXmlStreamReader &xml, Converter::Options options
} }
QXmlStreamAttributes attrs = xml.attributes(); QXmlStreamAttributes attrs = xml.attributes();
QStringRef type = attrs.value(QLatin1String("type")); QStringView type = attrs.value(QLatin1String("type"));
forever { forever {
xml.readNext(); xml.readNext();
@ -222,7 +222,7 @@ static QVariant variantFromXml(QXmlStreamReader &xml, Converter::Options options
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
QStringRef text = xml.text(); QStringView text = xml.text();
if (!xml.isCDATA()) if (!xml.isCDATA())
text = text.trimmed(); text = text.trimmed();
@ -247,7 +247,7 @@ static QVariant variantFromXml(QXmlStreamReader &xml, Converter::Options options
} }
} else if (type == QLatin1String("bytes")) { } else if (type == QLatin1String("bytes")) {
QByteArray data = text.toLatin1(); QByteArray data = text.toLatin1();
QStringRef encoding = attrs.value("encoding"); QStringView encoding = attrs.value("encoding");
if (encoding == QLatin1String("base64url")) { if (encoding == QLatin1String("base64url")) {
result = QByteArray::fromBase64(data, QByteArray::Base64UrlEncoding); result = QByteArray::fromBase64(data, QByteArray::Base64UrlEncoding);
} else if (encoding == QLatin1String("hex")) { } else if (encoding == QLatin1String("hex")) {

View File

@ -265,20 +265,20 @@ private:
xml.readNext(); xml.readNext();
if (xml.tokenType() == QXmlStreamReader::StartElement) { if (xml.tokenType() == QXmlStreamReader::StartElement) {
QStringRef className = xml.attributes().value("class"); auto className = xml.attributes().value("class");
inFlightName |= xml.name() == "h1"; inFlightName |= xml.name() == u"h1";
inFlightStatus |= className == "FlightDetailHeaderStatus"; inFlightStatus |= className == u"FlightDetailHeaderStatus";
inFlightMap |= className == "flightMap"; inFlightMap |= className == u"flightMap";
if (xml.name() == "td" && !className.isEmpty()) { if (xml.name() == u"td" && !className.isEmpty()) {
if (className.contains("fieldTitle")) { if (className.contains(u"fieldTitle")) {
inFieldName = true; inFieldName = true;
fieldNames += QString(); fieldNames += QString();
fieldValues += QString(); fieldValues += QString();
} }
if (className.contains("fieldValue")) if (className.contains(u"fieldValue"))
inFieldValue = true; inFieldValue = true;
} }
if (xml.name() == "img" && inFlightMap) { if (xml.name() == u"img" && inFlightMap) {
const QByteArray encoded const QByteArray encoded
= ("http://mobile.flightview.com/" % xml.attributes().value("src")).toLatin1(); = ("http://mobile.flightview.com/" % xml.attributes().value("src")).toLatin1();
QUrl url = QUrl::fromPercentEncoding(encoded); QUrl url = QUrl::fromPercentEncoding(encoded);
@ -287,11 +287,11 @@ private:
} }
if (xml.tokenType() == QXmlStreamReader::EndElement) { if (xml.tokenType() == QXmlStreamReader::EndElement) {
inFlightName &= xml.name() != "h1"; inFlightName &= xml.name() != u"h1";
inFlightStatus &= xml.name() != "div"; inFlightStatus &= xml.name() != u"div";
inFlightMap &= xml.name() != "div"; inFlightMap &= xml.name() != u"div";
inFieldName &= xml.name() != "td"; inFieldName &= xml.name() != u"td";
inFieldValue &= xml.name() != "td"; inFieldValue &= xml.name() != u"td";
} }
if (xml.tokenType() == QXmlStreamReader::Characters) { if (xml.tokenType() == QXmlStreamReader::Characters) {

View File

@ -217,8 +217,8 @@ void GSuggestCompletion::handleNetworkData(QNetworkReply *networkReply)
while (!xml.atEnd()) { while (!xml.atEnd()) {
xml.readNext(); xml.readNext();
if (xml.tokenType() == QXmlStreamReader::StartElement) if (xml.tokenType() == QXmlStreamReader::StartElement)
if (xml.name() == "suggestion") { if (xml.name() == u"suggestion") {
QStringRef str = xml.attributes().value("data"); auto str = xml.attributes().value("data");
choices << str.toString(); choices << str.toString();
} }
} }

View File

@ -103,21 +103,21 @@ GraphicsScene::GraphicsScene(int x, int y, int width, int height, Mode mode, QOb
while (!reader.atEnd()) { while (!reader.atEnd()) {
reader.readNext(); reader.readNext();
if (reader.tokenType() == QXmlStreamReader::StartElement) { if (reader.tokenType() == QXmlStreamReader::StartElement) {
if (reader.name() == "submarine") { if (reader.name() == u"submarine") {
SubmarineDescription desc; SubmarineDescription desc;
desc.name = reader.attributes().value("name").toString(); desc.name = reader.attributes().value("name").toString();
desc.points = reader.attributes().value("points").toInt(); desc.points = reader.attributes().value("points").toInt();
desc.type = reader.attributes().value("type").toInt(); desc.type = reader.attributes().value("type").toInt();
submarinesData.append(desc); submarinesData.append(desc);
} else if (reader.name() == "level") { } else if (reader.name() == u"level") {
currentLevel.id = reader.attributes().value("id").toInt(); currentLevel.id = reader.attributes().value("id").toInt();
currentLevel.name = reader.attributes().value("name").toString(); currentLevel.name = reader.attributes().value("name").toString();
} else if (reader.name() == "subinstance") { } else if (reader.name() == u"subinstance") {
currentLevel.submarines.append(qMakePair(reader.attributes().value("type").toInt(), currentLevel.submarines.append(qMakePair(reader.attributes().value("type").toInt(),
reader.attributes().value("nb").toInt())); reader.attributes().value("nb").toInt()));
} }
} else if (reader.tokenType() == QXmlStreamReader::EndElement) { } else if (reader.tokenType() == QXmlStreamReader::EndElement) {
if (reader.name() == "level") { if (reader.name() == u"level") {
levelsData.insert(currentLevel.id, currentLevel); levelsData.insert(currentLevel.id, currentLevel);
currentLevel.submarines.clear(); currentLevel.submarines.clear();
} }

View File

@ -214,11 +214,11 @@ void RSSListing::parseXml()
while (!xml.atEnd()) { while (!xml.atEnd()) {
xml.readNext(); xml.readNext();
if (xml.isStartElement()) { if (xml.isStartElement()) {
if (xml.name() == "item") if (xml.name() == u"item")
linkString = xml.attributes().value("rss:about").toString(); linkString = xml.attributes().value("rss:about").toString();
currentTag = xml.name().toString(); currentTag = xml.name().toString();
} else if (xml.isEndElement()) { } else if (xml.isEndElement()) {
if (xml.name() == "item") { if (xml.name() == u"item") {
QTreeWidgetItem *item = new QTreeWidgetItem; QTreeWidgetItem *item = new QTreeWidgetItem;
item->setText(0, titleString); item->setText(0, titleString);

View File

@ -517,14 +517,14 @@ void QMimeBinaryProvider::loadMimeTypePrivate(QMimeTypePrivate &data)
if (xml.name() != QLatin1String("mime-type")) { if (xml.name() != QLatin1String("mime-type")) {
continue; continue;
} }
const QStringRef name = xml.attributes().value(QLatin1String("type")); const auto name = xml.attributes().value(QLatin1String("type"));
if (name.isEmpty()) if (name.isEmpty())
continue; continue;
if (name.compare(data.name, Qt::CaseInsensitive)) if (name.compare(data.name, Qt::CaseInsensitive))
qWarning() << "Got name" << name << "in file" << file << "expected" << data.name; qWarning() << "Got name" << name << "in file" << file << "expected" << data.name;
while (xml.readNextStartElement()) { while (xml.readNextStartElement()) {
const QStringRef tag = xml.name(); const auto tag = xml.name();
if (tag == QLatin1String("comment")) { if (tag == QLatin1String("comment")) {
QString lang = xml.attributes().value(QLatin1String("xml:lang")).toString(); QString lang = xml.attributes().value(QLatin1String("xml:lang")).toString();
const QString text = xml.readElementText(); const QString text = xml.readElementText();

View File

@ -107,7 +107,7 @@ static const char matchMaskAttributeC[] = "mask";
Overwrite to process the sequence of parsed data Overwrite to process the sequence of parsed data
*/ */
QMimeTypeParserBase::ParseState QMimeTypeParserBase::nextState(ParseState currentState, const QStringRef &startElement) QMimeTypeParserBase::ParseState QMimeTypeParserBase::nextState(ParseState currentState, QStringView startElement)
{ {
switch (currentState) { switch (currentState) {
case ParseBeginning: case ParseBeginning:
@ -174,7 +174,7 @@ struct CreateMagicMatchRuleResult {
QString errorMessage; // must be first QString errorMessage; // must be first
QMimeMagicRule rule; QMimeMagicRule rule;
CreateMagicMatchRuleResult(const QStringRef &type, const QStringRef &value, const QStringRef &offsets, const QStringRef &mask) CreateMagicMatchRuleResult(QStringView type, QStringView value, QStringView offsets, QStringView mask)
: errorMessage(), rule(type.toString(), value.toUtf8(), offsets.toString(), mask.toLatin1(), &errorMessage) : errorMessage(), rule(type.toString(), value.toUtf8(), offsets.toString(), mask.toLatin1(), &errorMessage)
{ {
@ -183,10 +183,10 @@ struct CreateMagicMatchRuleResult {
static CreateMagicMatchRuleResult createMagicMatchRule(const QXmlStreamAttributes &atts) static CreateMagicMatchRuleResult createMagicMatchRule(const QXmlStreamAttributes &atts)
{ {
const QStringRef type = atts.value(QLatin1String(matchTypeAttributeC)); const auto type = atts.value(QLatin1String(matchTypeAttributeC));
const QStringRef value = atts.value(QLatin1String(matchValueAttributeC)); const auto value = atts.value(QLatin1String(matchValueAttributeC));
const QStringRef offsets = atts.value(QLatin1String(matchOffsetAttributeC)); const auto offsets = atts.value(QLatin1String(matchOffsetAttributeC));
const QStringRef mask = atts.value(QLatin1String(matchMaskAttributeC)); const auto mask = atts.value(QLatin1String(matchMaskAttributeC));
return CreateMagicMatchRuleResult(type, value, offsets, mask); return CreateMagicMatchRuleResult(type, value, offsets, mask);
} }
#endif #endif
@ -265,7 +265,7 @@ bool QMimeTypeParserBase::parse(QIODevice *dev, const QString &fileName, QString
break; break;
case ParseMagic: { case ParseMagic: {
priority = 50; priority = 50;
const QStringRef priorityS = atts.value(QLatin1String(priorityAttributeC)); const auto priorityS = atts.value(QLatin1String(priorityAttributeC));
if (!priorityS.isEmpty()) { if (!priorityS.isEmpty()) {
if (!parseNumber(priorityS, &priority, errorMessage)) if (!parseNumber(priorityS, &priority, errorMessage))
return false; return false;
@ -301,7 +301,7 @@ bool QMimeTypeParserBase::parse(QIODevice *dev, const QString &fileName, QString
// continue switch QXmlStreamReader::Token... // continue switch QXmlStreamReader::Token...
case QXmlStreamReader::EndElement: // Finished element case QXmlStreamReader::EndElement: // Finished element
{ {
const QStringRef elementName = reader.name(); const auto elementName = reader.name();
if (elementName == QLatin1String(mimeTypeTagC)) { if (elementName == QLatin1String(mimeTypeTagC)) {
if (!process(QMimeType(data), errorMessage)) if (!process(QMimeType(data), errorMessage))
return false; return false;

View File

@ -98,7 +98,7 @@ private:
ParseError ParseError
}; };
static ParseState nextState(ParseState currentState, const QStringRef &startElement); static ParseState nextState(ParseState currentState, QStringView startElement);
}; };

View File

@ -384,13 +384,9 @@ QXmlStreamEntityResolver *QXmlStreamReader::entityResolver() const
token at the time it is reported. In addition, QXmlStreamReader token at the time it is reported. In addition, QXmlStreamReader
avoids the many small string allocations that it normally takes to avoids the many small string allocations that it normally takes to
map an XML document to a convenient and Qt-ish API. It does this by map an XML document to a convenient and Qt-ish API. It does this by
reporting all string data as QStringRef rather than real QString reporting all string data as QStringView rather than real QString
objects. QStringRef is a thin wrapper around QString substrings that objects. Calling \l{QStringView::toString()}{toString()} on any of
provides a subset of the QString API without the memory allocation those objects returns an equivalent real QString object.
and reference-counting overhead. Calling
\l{QStringRef::toString()}{toString()} on any of those objects
returns an equivalent real QString object.
*/ */
@ -1928,7 +1924,7 @@ qint64 QXmlStreamReader::characterOffset() const
/*! Returns the text of \l Characters, \l Comment, \l DTD, or /*! Returns the text of \l Characters, \l Comment, \l DTD, or
EntityReference. EntityReference.
*/ */
QStringRef QXmlStreamReader::text() const QStringView QXmlStreamReader::text() const
{ {
Q_D(const QXmlStreamReader); Q_D(const QXmlStreamReader);
return d->text; return d->text;
@ -1971,12 +1967,12 @@ QXmlStreamEntityDeclarations QXmlStreamReader::entityDeclarations() const
name. Otherwise an empty string is returned. name. Otherwise an empty string is returned.
*/ */
QStringRef QXmlStreamReader::dtdName() const QStringView QXmlStreamReader::dtdName() const
{ {
Q_D(const QXmlStreamReader); Q_D(const QXmlStreamReader);
if (d->type == QXmlStreamReader::DTD) if (d->type == QXmlStreamReader::DTD)
return d->dtdName; return d->dtdName;
return QStringRef(); return QStringView();
} }
/*! /*!
@ -1986,12 +1982,12 @@ QStringRef QXmlStreamReader::dtdName() const
public identifier. Otherwise an empty string is returned. public identifier. Otherwise an empty string is returned.
*/ */
QStringRef QXmlStreamReader::dtdPublicId() const QStringView QXmlStreamReader::dtdPublicId() const
{ {
Q_D(const QXmlStreamReader); Q_D(const QXmlStreamReader);
if (d->type == QXmlStreamReader::DTD) if (d->type == QXmlStreamReader::DTD)
return d->dtdPublicId; return d->dtdPublicId;
return QStringRef(); return QStringView();
} }
/*! /*!
@ -2001,12 +1997,12 @@ QStringRef QXmlStreamReader::dtdPublicId() const
system identifier. Otherwise an empty string is returned. system identifier. Otherwise an empty string is returned.
*/ */
QStringRef QXmlStreamReader::dtdSystemId() const QStringView QXmlStreamReader::dtdSystemId() const
{ {
Q_D(const QXmlStreamReader); Q_D(const QXmlStreamReader);
if (d->type == QXmlStreamReader::DTD) if (d->type == QXmlStreamReader::DTD)
return d->dtdSystemId; return d->dtdSystemId;
return QStringRef(); return QStringView();
} }
/*! /*!
@ -2187,7 +2183,7 @@ QXmlStreamReader::Error QXmlStreamReader::error() const
/*! /*!
Returns the target of a ProcessingInstruction. Returns the target of a ProcessingInstruction.
*/ */
QStringRef QXmlStreamReader::processingInstructionTarget() const QStringView QXmlStreamReader::processingInstructionTarget() const
{ {
Q_D(const QXmlStreamReader); Q_D(const QXmlStreamReader);
return d->processingInstructionTarget; return d->processingInstructionTarget;
@ -2196,7 +2192,7 @@ QStringRef QXmlStreamReader::processingInstructionTarget() const
/*! /*!
Returns the data of a ProcessingInstruction. Returns the data of a ProcessingInstruction.
*/ */
QStringRef QXmlStreamReader::processingInstructionData() const QStringView QXmlStreamReader::processingInstructionData() const
{ {
Q_D(const QXmlStreamReader); Q_D(const QXmlStreamReader);
return d->processingInstructionData; return d->processingInstructionData;
@ -2209,7 +2205,7 @@ QStringRef QXmlStreamReader::processingInstructionData() const
\sa namespaceUri(), qualifiedName() \sa namespaceUri(), qualifiedName()
*/ */
QStringRef QXmlStreamReader::name() const QStringView QXmlStreamReader::name() const
{ {
Q_D(const QXmlStreamReader); Q_D(const QXmlStreamReader);
return d->name; return d->name;
@ -2220,7 +2216,7 @@ QStringRef QXmlStreamReader::name() const
\sa name(), qualifiedName() \sa name(), qualifiedName()
*/ */
QStringRef QXmlStreamReader::namespaceUri() const QStringView QXmlStreamReader::namespaceUri() const
{ {
Q_D(const QXmlStreamReader); Q_D(const QXmlStreamReader);
return d->namespaceUri; return d->namespaceUri;
@ -2238,7 +2234,7 @@ QStringRef QXmlStreamReader::namespaceUri() const
\sa name(), prefix(), namespaceUri() \sa name(), prefix(), namespaceUri()
*/ */
QStringRef QXmlStreamReader::qualifiedName() const QStringView QXmlStreamReader::qualifiedName() const
{ {
Q_D(const QXmlStreamReader); Q_D(const QXmlStreamReader);
return d->qualifiedName; return d->qualifiedName;
@ -2253,7 +2249,7 @@ QStringRef QXmlStreamReader::qualifiedName() const
\sa name(), qualifiedName() \sa name(), qualifiedName()
*/ */
QStringRef QXmlStreamReader::prefix() const QStringView QXmlStreamReader::prefix() const
{ {
Q_D(const QXmlStreamReader); Q_D(const QXmlStreamReader);
return d->prefix; return d->prefix;
@ -2317,15 +2313,15 @@ QXmlStreamAttribute::QXmlStreamAttribute(const QString &qualifiedName, const QSt
m_value = QXmlStreamStringRef(QStringRef(&value)); m_value = QXmlStreamStringRef(QStringRef(&value));
} }
/*! \fn QStringRef QXmlStreamAttribute::namespaceUri() const /*! \fn QStringView QXmlStreamAttribute::namespaceUri() const
Returns the attribute's resolved namespaceUri, or an empty string Returns the attribute's resolved namespaceUri, or an empty string
reference if the attribute does not have a defined namespace. reference if the attribute does not have a defined namespace.
*/ */
/*! \fn QStringRef QXmlStreamAttribute::name() const /*! \fn QStringView QXmlStreamAttribute::name() const
Returns the attribute's local name. Returns the attribute's local name.
*/ */
/*! \fn QStringRef QXmlStreamAttribute::qualifiedName() const /*! \fn QStringView QXmlStreamAttribute::qualifiedName() const
Returns the attribute's qualified name. Returns the attribute's qualified name.
A qualified name is the raw name of an attribute in the XML A qualified name is the raw name of an attribute in the XML
@ -2337,7 +2333,7 @@ QXmlStreamAttribute::QXmlStreamAttribute(const QString &qualifiedName, const QSt
the attribute's local name(). the attribute's local name().
*/ */
/*! /*!
\fn QStringRef QXmlStreamAttribute::prefix() const \fn QStringView QXmlStreamAttribute::prefix() const
\since 4.4 \since 4.4
Returns the attribute's namespace prefix. Returns the attribute's namespace prefix.
@ -2345,7 +2341,7 @@ QXmlStreamAttribute::QXmlStreamAttribute(const QString &qualifiedName, const QSt
*/ */
/*! \fn QStringRef QXmlStreamAttribute::value() const /*! \fn QStringView QXmlStreamAttribute::value() const
Returns the attribute's value. Returns the attribute's value.
*/ */
@ -2421,15 +2417,15 @@ QXmlStreamNotationDeclaration::QXmlStreamNotationDeclaration()
{ {
} }
/*! \fn QStringRef QXmlStreamNotationDeclaration::name() const /*! \fn QStringView QXmlStreamNotationDeclaration::name() const
Returns the notation name. Returns the notation name.
*/ */
/*! \fn QStringRef QXmlStreamNotationDeclaration::systemId() const /*! \fn QStringView QXmlStreamNotationDeclaration::systemId() const
Returns the system identifier. Returns the system identifier.
*/ */
/*! \fn QStringRef QXmlStreamNotationDeclaration::publicId() const /*! \fn QStringView QXmlStreamNotationDeclaration::publicId() const
Returns the public identifier. Returns the public identifier.
*/ */
@ -2492,11 +2488,11 @@ QXmlStreamNamespaceDeclaration::QXmlStreamNamespaceDeclaration(const QString &pr
m_namespaceUri = namespaceUri; m_namespaceUri = namespaceUri;
} }
/*! \fn QStringRef QXmlStreamNamespaceDeclaration::prefix() const /*! \fn QStringView QXmlStreamNamespaceDeclaration::prefix() const
Returns the prefix. Returns the prefix.
*/ */
/*! \fn QStringRef QXmlStreamNamespaceDeclaration::namespaceUri() const /*! \fn QStringView QXmlStreamNamespaceDeclaration::namespaceUri() const
Returns the namespaceUri. Returns the namespaceUri.
*/ */
@ -2545,23 +2541,23 @@ QXmlStreamEntityDeclaration::QXmlStreamEntityDeclaration()
This function is very fast and never fails. This function is very fast and never fails.
*/ */
/*! \fn QStringRef QXmlStreamEntityDeclaration::name() const /*! \fn QStringView QXmlStreamEntityDeclaration::name() const
Returns the entity name. Returns the entity name.
*/ */
/*! \fn QStringRef QXmlStreamEntityDeclaration::notationName() const /*! \fn QStringView QXmlStreamEntityDeclaration::notationName() const
Returns the notation name. Returns the notation name.
*/ */
/*! \fn QStringRef QXmlStreamEntityDeclaration::systemId() const /*! \fn QStringView QXmlStreamEntityDeclaration::systemId() const
Returns the system identifier. Returns the system identifier.
*/ */
/*! \fn QStringRef QXmlStreamEntityDeclaration::publicId() const /*! \fn QStringView QXmlStreamEntityDeclaration::publicId() const
Returns the public identifier. Returns the public identifier.
*/ */
/*! \fn QStringRef QXmlStreamEntityDeclaration::value() const /*! \fn QStringView QXmlStreamEntityDeclaration::value() const
Returns the entity's value. Returns the entity's value.
*/ */
@ -2581,13 +2577,13 @@ Returns the entity's value.
described with \a namespaceUri, or an empty string reference if the described with \a namespaceUri, or an empty string reference if the
attribute is not defined. The \a namespaceUri can be empty. attribute is not defined. The \a namespaceUri can be empty.
*/ */
QStringRef QXmlStreamAttributes::value(const QString &namespaceUri, const QString &name) const QStringView QXmlStreamAttributes::value(const QString &namespaceUri, const QString &name) const
{ {
for (const QXmlStreamAttribute &attribute : *this) { for (const QXmlStreamAttribute &attribute : *this) {
if (attribute.name() == name && attribute.namespaceUri() == namespaceUri) if (attribute.name() == name && attribute.namespaceUri() == namespaceUri)
return attribute.value(); return attribute.value();
} }
return QStringRef(); return QStringView();
} }
/*!\overload /*!\overload
@ -2595,13 +2591,13 @@ QStringRef QXmlStreamAttributes::value(const QString &namespaceUri, const QStrin
described with \a namespaceUri, or an empty string reference if the described with \a namespaceUri, or an empty string reference if the
attribute is not defined. The \a namespaceUri can be empty. attribute is not defined. The \a namespaceUri can be empty.
*/ */
QStringRef QXmlStreamAttributes::value(const QString &namespaceUri, QLatin1String name) const QStringView QXmlStreamAttributes::value(const QString &namespaceUri, QLatin1String name) const
{ {
for (const QXmlStreamAttribute &attribute : *this) { for (const QXmlStreamAttribute &attribute : *this) {
if (attribute.name() == name && attribute.namespaceUri() == namespaceUri) if (attribute.name() == name && attribute.namespaceUri() == namespaceUri)
return attribute.value(); return attribute.value();
} }
return QStringRef(); return QStringView();
} }
/*!\overload /*!\overload
@ -2609,13 +2605,13 @@ QStringRef QXmlStreamAttributes::value(const QString &namespaceUri, QLatin1Strin
described with \a namespaceUri, or an empty string reference if the described with \a namespaceUri, or an empty string reference if the
attribute is not defined. The \a namespaceUri can be empty. attribute is not defined. The \a namespaceUri can be empty.
*/ */
QStringRef QXmlStreamAttributes::value(QLatin1String namespaceUri, QLatin1String name) const QStringView QXmlStreamAttributes::value(QLatin1String namespaceUri, QLatin1String name) const
{ {
for (const QXmlStreamAttribute &attribute : *this) { for (const QXmlStreamAttribute &attribute : *this) {
if (attribute.name() == name && attribute.namespaceUri() == namespaceUri) if (attribute.name() == name && attribute.namespaceUri() == namespaceUri)
return attribute.value(); return attribute.value();
} }
return QStringRef(); return QStringView();
} }
/*!\overload /*!\overload
@ -2630,13 +2626,13 @@ QStringRef QXmlStreamAttributes::value(QLatin1String namespaceUri, QLatin1String
use qualified names, but a resolved namespaceUri and the attribute's use qualified names, but a resolved namespaceUri and the attribute's
local name. local name.
*/ */
QStringRef QXmlStreamAttributes::value(const QString &qualifiedName) const QStringView QXmlStreamAttributes::value(const QString &qualifiedName) const
{ {
for (const QXmlStreamAttribute &attribute : *this) { for (const QXmlStreamAttribute &attribute : *this) {
if (attribute.qualifiedName() == qualifiedName) if (attribute.qualifiedName() == qualifiedName)
return attribute.value(); return attribute.value();
} }
return QStringRef(); return QStringView();
} }
/*!\overload /*!\overload
@ -2651,13 +2647,13 @@ QStringRef QXmlStreamAttributes::value(const QString &qualifiedName) const
use qualified names, but a resolved namespaceUri and the attribute's use qualified names, but a resolved namespaceUri and the attribute's
local name. local name.
*/ */
QStringRef QXmlStreamAttributes::value(QLatin1String qualifiedName) const QStringView QXmlStreamAttributes::value(QLatin1String qualifiedName) const
{ {
for (const QXmlStreamAttribute &attribute : *this) { for (const QXmlStreamAttribute &attribute : *this) {
if (attribute.qualifiedName() == qualifiedName) if (attribute.qualifiedName() == qualifiedName)
return attribute.value(); return attribute.value();
} }
return QStringRef(); return QStringView();
} }
/*!Appends a new attribute with \a name in the namespace /*!Appends a new attribute with \a name in the namespace
@ -2754,12 +2750,12 @@ bool QXmlStreamReader::isStandaloneDocument() const
version string as specified in the XML declaration. version string as specified in the XML declaration.
Otherwise an empty string is returned. Otherwise an empty string is returned.
*/ */
QStringRef QXmlStreamReader::documentVersion() const QStringView QXmlStreamReader::documentVersion() const
{ {
Q_D(const QXmlStreamReader); Q_D(const QXmlStreamReader);
if (d->type == QXmlStreamReader::StartDocument) if (d->type == QXmlStreamReader::StartDocument)
return d->documentVersion; return d->documentVersion;
return QStringRef(); return QStringView();
} }
/*! /*!
@ -2769,12 +2765,12 @@ QStringRef QXmlStreamReader::documentVersion() const
encoding string as specified in the XML declaration. encoding string as specified in the XML declaration.
Otherwise an empty string is returned. Otherwise an empty string is returned.
*/ */
QStringRef QXmlStreamReader::documentEncoding() const QStringView QXmlStreamReader::documentEncoding() const
{ {
Q_D(const QXmlStreamReader); Q_D(const QXmlStreamReader);
if (d->type == QXmlStreamReader::StartDocument) if (d->type == QXmlStreamReader::StartDocument)
return d->documentEncoding; return d->documentEncoding;
return QStringRef(); return QStringView();
} }
#endif // QT_NO_XMLSTREAMREADER #endif // QT_NO_XMLSTREAMREADER

View File

@ -70,9 +70,11 @@ public:
inline void clear() { m_string.clear(); m_position = m_size = 0; } inline void clear() { m_string.clear(); m_position = m_size = 0; }
inline operator QStringRef() const { return QStringRef(&m_string, m_position, m_size); } inline operator QStringRef() const { return QStringRef(&m_string, m_position, m_size); }
inline operator QStringView() const { return QStringView(m_string.constData() + m_position, m_size); }
inline const QString *string() const { return &m_string; } inline const QString *string() const { return &m_string; }
inline int position() const { return m_position; } inline int position() const { return m_position; }
inline int size() const { return m_size; } inline int size() const { return m_size; }
inline QString toString() const { return QString(m_string.constData() + m_position, m_size); }
}; };
Q_DECLARE_SHARED(QXmlStreamStringRef) Q_DECLARE_SHARED(QXmlStreamStringRef)
@ -89,15 +91,14 @@ public:
QXmlStreamAttribute(const QString &qualifiedName, const QString &value); QXmlStreamAttribute(const QString &qualifiedName, const QString &value);
QXmlStreamAttribute(const QString &namespaceUri, const QString &name, const QString &value); QXmlStreamAttribute(const QString &namespaceUri, const QString &name, const QString &value);
inline QStringRef namespaceUri() const { return m_namespaceUri; } inline QStringView namespaceUri() const { return m_namespaceUri; }
inline QStringRef name() const { return m_name; } inline QStringView name() const { return m_name; }
inline QStringRef qualifiedName() const { return m_qualifiedName; } inline QStringView qualifiedName() const { return m_qualifiedName; }
inline QStringRef prefix() const { inline QStringView prefix() const {
return QStringRef(m_qualifiedName.string(), return QStringView(m_qualifiedName.string()->constData() + m_qualifiedName.position(),
m_qualifiedName.position(),
qMax(0, m_qualifiedName.size() - m_name.size() - 1)); qMax(0, m_qualifiedName.size() - m_name.size() - 1));
} }
inline QStringRef value() const { return m_value; } inline QStringView value() const { return m_value; }
inline bool isDefault() const { return m_isDefault; } inline bool isDefault() const { return m_isDefault; }
inline bool operator==(const QXmlStreamAttribute &other) const { inline bool operator==(const QXmlStreamAttribute &other) const {
return (value() == other.value() return (value() == other.value()
@ -116,11 +117,11 @@ class QXmlStreamAttributes : public QList<QXmlStreamAttribute>
{ {
public: public:
inline QXmlStreamAttributes() {} inline QXmlStreamAttributes() {}
Q_CORE_EXPORT QStringRef value(const QString &namespaceUri, const QString &name) const; Q_CORE_EXPORT QStringView value(const QString &namespaceUri, const QString &name) const;
Q_CORE_EXPORT QStringRef value(const QString &namespaceUri, QLatin1String name) const; Q_CORE_EXPORT QStringView value(const QString &namespaceUri, QLatin1String name) const;
Q_CORE_EXPORT QStringRef value(QLatin1String namespaceUri, QLatin1String name) const; Q_CORE_EXPORT QStringView value(QLatin1String namespaceUri, QLatin1String name) const;
Q_CORE_EXPORT QStringRef value(const QString &qualifiedName) const; Q_CORE_EXPORT QStringView value(const QString &qualifiedName) const;
Q_CORE_EXPORT QStringRef value(QLatin1String qualifiedName) const; Q_CORE_EXPORT QStringView value(QLatin1String qualifiedName) const;
Q_CORE_EXPORT void append(const QString &namespaceUri, const QString &name, const QString &value); Q_CORE_EXPORT void append(const QString &namespaceUri, const QString &name, const QString &value);
Q_CORE_EXPORT void append(const QString &qualifiedName, const QString &value); Q_CORE_EXPORT void append(const QString &qualifiedName, const QString &value);
@ -150,8 +151,8 @@ public:
QXmlStreamNamespaceDeclaration(); QXmlStreamNamespaceDeclaration();
QXmlStreamNamespaceDeclaration(const QString &prefix, const QString &namespaceUri); QXmlStreamNamespaceDeclaration(const QString &prefix, const QString &namespaceUri);
inline QStringRef prefix() const { return m_prefix; } inline QStringView prefix() const { return m_prefix; }
inline QStringRef namespaceUri() const { return m_namespaceUri; } inline QStringView namespaceUri() const { return m_namespaceUri; }
inline bool operator==(const QXmlStreamNamespaceDeclaration &other) const { inline bool operator==(const QXmlStreamNamespaceDeclaration &other) const {
return (prefix() == other.prefix() && namespaceUri() == other.namespaceUri()); return (prefix() == other.prefix() && namespaceUri() == other.namespaceUri());
} }
@ -169,9 +170,9 @@ class Q_CORE_EXPORT QXmlStreamNotationDeclaration {
public: public:
QXmlStreamNotationDeclaration(); QXmlStreamNotationDeclaration();
inline QStringRef name() const { return m_name; } inline QStringView name() const { return m_name; }
inline QStringRef systemId() const { return m_systemId; } inline QStringView systemId() const { return m_systemId; }
inline QStringRef publicId() const { return m_publicId; } inline QStringView publicId() const { return m_publicId; }
inline bool operator==(const QXmlStreamNotationDeclaration &other) const { inline bool operator==(const QXmlStreamNotationDeclaration &other) const {
return (name() == other.name() && systemId() == other.systemId() return (name() == other.name() && systemId() == other.systemId()
&& publicId() == other.publicId()); && publicId() == other.publicId());
@ -190,11 +191,11 @@ class Q_CORE_EXPORT QXmlStreamEntityDeclaration {
public: public:
QXmlStreamEntityDeclaration(); QXmlStreamEntityDeclaration();
inline QStringRef name() const { return m_name; } inline QStringView name() const { return m_name; }
inline QStringRef notationName() const { return m_notationName; } inline QStringView notationName() const { return m_notationName; }
inline QStringRef systemId() const { return m_systemId; } inline QStringView systemId() const { return m_systemId; }
inline QStringRef publicId() const { return m_publicId; } inline QStringView publicId() const { return m_publicId; }
inline QStringRef value() const { return m_value; } inline QStringView value() const { return m_value; }
inline bool operator==(const QXmlStreamEntityDeclaration &other) const { inline bool operator==(const QXmlStreamEntityDeclaration &other) const {
return (name() == other.name() return (name() == other.name()
&& notationName() == other.notationName() && notationName() == other.notationName()
@ -276,8 +277,8 @@ public:
inline bool isProcessingInstruction() const { return tokenType() == ProcessingInstruction; } inline bool isProcessingInstruction() const { return tokenType() == ProcessingInstruction; }
bool isStandaloneDocument() const; bool isStandaloneDocument() const;
QStringRef documentVersion() const; QStringView documentVersion() const;
QStringRef documentEncoding() const; QStringView documentEncoding() const;
qint64 lineNumber() const; qint64 lineNumber() const;
qint64 columnNumber() const; qint64 columnNumber() const;
@ -292,24 +293,24 @@ public:
}; };
QString readElementText(ReadElementTextBehaviour behaviour = ErrorOnUnexpectedElement); QString readElementText(ReadElementTextBehaviour behaviour = ErrorOnUnexpectedElement);
QStringRef name() const; QStringView name() const;
QStringRef namespaceUri() const; QStringView namespaceUri() const;
QStringRef qualifiedName() const; QStringView qualifiedName() const;
QStringRef prefix() const; QStringView prefix() const;
QStringRef processingInstructionTarget() const; QStringView processingInstructionTarget() const;
QStringRef processingInstructionData() const; QStringView processingInstructionData() const;
QStringRef text() const; QStringView text() const;
QXmlStreamNamespaceDeclarations namespaceDeclarations() const; QXmlStreamNamespaceDeclarations namespaceDeclarations() const;
void addExtraNamespaceDeclaration(const QXmlStreamNamespaceDeclaration &extraNamespaceDeclaraction); void addExtraNamespaceDeclaration(const QXmlStreamNamespaceDeclaration &extraNamespaceDeclaraction);
void addExtraNamespaceDeclarations(const QXmlStreamNamespaceDeclarations &extraNamespaceDeclaractions); void addExtraNamespaceDeclarations(const QXmlStreamNamespaceDeclarations &extraNamespaceDeclaractions);
QXmlStreamNotationDeclarations notationDeclarations() const; QXmlStreamNotationDeclarations notationDeclarations() const;
QXmlStreamEntityDeclarations entityDeclarations() const; QXmlStreamEntityDeclarations entityDeclarations() const;
QStringRef dtdName() const; QStringView dtdName() const;
QStringRef dtdPublicId() const; QStringView dtdPublicId() const;
QStringRef dtdSystemId() const; QStringView dtdSystemId() const;
int entityExpansionLimit() const; int entityExpansionLimit() const;
void setEntityExpansionLimit(int limit); void setEntityExpansionLimit(int limit);

View File

@ -104,7 +104,7 @@ void VkSpecParser::parseCommands()
m_reader.readNext(); m_reader.readNext();
if (m_reader.isEndElement() && m_reader.name() == QStringLiteral("commands")) if (m_reader.isEndElement() && m_reader.name() == QStringLiteral("commands"))
return; return;
if (m_reader.isStartElement() && m_reader.name() == "command") if (m_reader.isStartElement() && m_reader.name() == u"command")
m_commands.append(parseCommand()); m_commands.append(parseCommand());
} }
} }
@ -162,7 +162,7 @@ VkSpecParser::TypedName VkSpecParser::parseParamOrProto(const QString &tag)
skip(); skip();
} }
} else { } else {
QStringRef text = m_reader.text().trimmed(); auto text = m_reader.text().trimmed();
if (!text.isEmpty()) { if (!text.isEmpty()) {
if (text.startsWith(QLatin1Char('['))) { if (text.startsWith(QLatin1Char('['))) {
t.typeSuffix += text; t.typeSuffix += text;

View File

@ -172,7 +172,7 @@ static double versionFromUiAttribute(QXmlStreamReader &reader)
const QString versionAttribute = QLatin1String("version"); const QString versionAttribute = QLatin1String("version");
if (!attributes.hasAttribute(versionAttribute)) if (!attributes.hasAttribute(versionAttribute))
return 4.0; return 4.0;
const QStringRef version = attributes.value(versionAttribute); const QStringView version = attributes.value(versionAttribute);
return version.toDouble(); return version.toDouble();
} }

View File

@ -291,15 +291,6 @@ QT_WARNING_POP
#endif // QT_DEPRECATED_SINCE(5, 15) #endif // QT_DEPRECATED_SINCE(5, 15)
inline QString stringRefToString(const QStringRef &stringRef)
{
// Calling QStringRef::toString() on a NULL QStringRef in some cases returns
// an empty string (i.e. QString("")) instead of a NULL string (i.e. QString()).
// QDom implementation differentiates between NULL and empty strings, so
// we need this as workaround to keep the current behavior unchanged.
return stringRef.isNull() ? QString() : stringRef.toString();
}
bool QDomBuilder::startElement(const QString &nsURI, const QString &qName, bool QDomBuilder::startElement(const QString &nsURI, const QString &qName,
const QXmlStreamAttributes &atts) const QXmlStreamAttributes &atts)
{ {
@ -317,12 +308,12 @@ bool QDomBuilder::startElement(const QString &nsURI, const QString &qName,
for (const auto &attr : atts) { for (const auto &attr : atts) {
auto domElement = static_cast<QDomElementPrivate *>(node); auto domElement = static_cast<QDomElementPrivate *>(node);
if (nsProcessing) { if (nsProcessing) {
domElement->setAttributeNS(stringRefToString(attr.namespaceUri()), domElement->setAttributeNS(attr.namespaceUri().toString(),
stringRefToString(attr.qualifiedName()), attr.qualifiedName().toString(),
stringRefToString(attr.value())); attr.value().toString());
} else { } else {
domElement->setAttribute(stringRefToString(attr.qualifiedName()), domElement->setAttribute(attr.qualifiedName().toString(),
stringRefToString(attr.value())); attr.value().toString());
} }
} }
@ -513,9 +504,9 @@ bool QDomParser::parseProlog()
} }
foundDtd = true; foundDtd = true;
if (!domBuilder.startDTD(stringRefToString(reader->dtdName()), if (!domBuilder.startDTD(reader->dtdName().toString(),
stringRefToString(reader->dtdPublicId()), reader->dtdPublicId().toString(),
stringRefToString(reader->dtdSystemId()))) { reader->dtdSystemId().toString())) {
domBuilder.fatalError( domBuilder.fatalError(
QDomParser::tr("Error occurred while processing document type declaration")); QDomParser::tr("Error occurred while processing document type declaration"));
return false; return false;
@ -550,13 +541,13 @@ bool QDomParser::parseBody()
{ {
Q_ASSERT(reader); Q_ASSERT(reader);
std::stack<QStringRef> tagStack; std::stack<QString> tagStack;
while (!reader->atEnd() && !reader->hasError()) { while (!reader->atEnd() && !reader->hasError()) {
switch (reader->tokenType()) { switch (reader->tokenType()) {
case QXmlStreamReader::StartElement: case QXmlStreamReader::StartElement:
tagStack.push(reader->qualifiedName()); tagStack.push(reader->qualifiedName().toString());
if (!domBuilder.startElement(stringRefToString(reader->namespaceUri()), if (!domBuilder.startElement(reader->namespaceUri().toString(),
stringRefToString(reader->qualifiedName()), reader->qualifiedName().toString(),
reader->attributes())) { reader->attributes())) {
domBuilder.fatalError( domBuilder.fatalError(
QDomParser::tr("Error occurred while processing a start element")); QDomParser::tr("Error occurred while processing a start element"));
@ -641,10 +632,10 @@ bool QDomParser::parseMarkupDecl()
// parsed result. So we don't need to do anything for the Internal Entities. // parsed result. So we don't need to do anything for the Internal Entities.
if (!entityDecl.publicId().isEmpty() || !entityDecl.systemId().isEmpty()) { if (!entityDecl.publicId().isEmpty() || !entityDecl.systemId().isEmpty()) {
// External Entity // External Entity
if (!domBuilder.unparsedEntityDecl(stringRefToString(entityDecl.name()), if (!domBuilder.unparsedEntityDecl(entityDecl.name().toString(),
stringRefToString(entityDecl.publicId()), entityDecl.publicId().toString(),
stringRefToString(entityDecl.systemId()), entityDecl.systemId().toString(),
stringRefToString(entityDecl.notationName()))) { entityDecl.notationName().toString())) {
domBuilder.fatalError( domBuilder.fatalError(
QDomParser::tr("Error occurred while processing entity declaration")); QDomParser::tr("Error occurred while processing entity declaration"));
return false; return false;
@ -654,9 +645,9 @@ bool QDomParser::parseMarkupDecl()
const auto notations = reader->notationDeclarations(); const auto notations = reader->notationDeclarations();
for (const auto &notationDecl : notations) { for (const auto &notationDecl : notations) {
if (!domBuilder.notationDecl(stringRefToString(notationDecl.name()), if (!domBuilder.notationDecl(notationDecl.name().toString(),
stringRefToString(notationDecl.publicId()), notationDecl.publicId().toString(),
stringRefToString(notationDecl.systemId()))) { notationDecl.systemId().toString())) {
domBuilder.fatalError( domBuilder.fatalError(
QDomParser::tr("Error occurred while processing notation declaration")); QDomParser::tr("Error occurred while processing notation declaration"));
return false; return false;