summaryrefslogtreecommitdiffstats
path: root/src/xml/sax/qxml.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/xml/sax/qxml.cpp')
-rw-r--r--src/xml/sax/qxml.cpp79
1 files changed, 49 insertions, 30 deletions
diff --git a/src/xml/sax/qxml.cpp b/src/xml/sax/qxml.cpp
index 97a3b070d8..d4c8519d67 100644
--- a/src/xml/sax/qxml.cpp
+++ b/src/xml/sax/qxml.cpp
@@ -1,31 +1,37 @@
/****************************************************************************
**
-** Copyright (C) 2015 The Qt Company Ltd.
-** Contact: http://www.qt.io/licensing/
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtXml module of the Qt Toolkit.
**
-** $QT_BEGIN_LICENSE:LGPL21$
+** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://www.qt.io/contact-us.
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 or version 3 as published by the Free
-** Software Foundation and appearing in the file LICENSE.LGPLv21 and
-** LICENSE.LGPLv3 included in the packaging of this file. Please review the
-** following information to ensure the GNU Lesser General Public License
-** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
-** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
**
-** As a special exception, The Qt Company gives you certain additional
-** rights. These rights are described in The Qt Company LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
@@ -75,6 +81,14 @@
QT_BEGIN_NAMESPACE
+namespace {
+
+// work around missing std::stack::clear()
+template <typename Container>
+void clear(Container &c) { c = Container(); }
+
+}
+
// the constants for the lookup table
static const signed char cltWS = 0; // white space
static const signed char cltPer = 1; // %
@@ -3197,7 +3211,7 @@ bool QXmlSimpleReader::parse(const QXmlInputSource *input, bool incremental)
d->contentHnd->setDocumentLocator(d->locator.data());
if (!d->contentHnd->startDocument()) {
d->reportParseError(d->contentHnd->errorString());
- d->tags.clear();
+ clear(d->tags);
return false;
}
}
@@ -3253,7 +3267,7 @@ bool QXmlSimpleReaderPrivate::parseBeginOrContinue(int state, bool incremental)
pushParseState(0, 0);
return true;
} else {
- tags.clear();
+ clear(tags);
return false;
}
}
@@ -3265,7 +3279,7 @@ bool QXmlSimpleReaderPrivate::parseBeginOrContinue(int state, bool incremental)
pushParseState(0, 1);
return true;
} else {
- tags.clear();
+ clear(tags);
return false;
}
}
@@ -3278,7 +3292,7 @@ bool QXmlSimpleReaderPrivate::parseBeginOrContinue(int state, bool incremental)
pushParseState(0, 2);
return true;
} else {
- tags.clear();
+ clear(tags);
return false;
}
}
@@ -3289,9 +3303,9 @@ bool QXmlSimpleReaderPrivate::parseBeginOrContinue(int state, bool incremental)
return true;
}
// is stack empty?
- if (!tags.isEmpty() && !error.isNull()) {
+ if (!tags.empty() && !error.isNull()) {
reportParseError(QLatin1String(XMLERR_UNEXPECTEDEOF));
- tags.clear();
+ clear(tags);
return false;
}
// call the handler
@@ -3697,16 +3711,15 @@ bool QXmlSimpleReaderPrivate::parseElement()
case STagEnd:
// call the handler
if (contentHnd) {
- const QString &tagsTop = tags.top();
if (useNamespaces) {
QString uri, lname;
- namespaceSupport.processName(tagsTop, false, uri, lname);
- if (!contentHnd->startElement(uri, lname, tagsTop, attList)) {
+ namespaceSupport.processName(tags.top(), false, uri, lname);
+ if (!contentHnd->startElement(uri, lname, tags.top(), attList)) {
reportParseError(contentHnd->errorString());
return false;
}
} else {
- if (!contentHnd->startElement(QString(), QString(), tagsTop, attList)) {
+ if (!contentHnd->startElement(QString(), QString(), tags.top(), attList)) {
reportParseError(contentHnd->errorString());
return false;
}
@@ -3732,7 +3745,7 @@ bool QXmlSimpleReaderPrivate::parseElement()
}
break;
case EmptyTag:
- if (tags.isEmpty()) {
+ if (tags.empty()) {
reportParseError(QLatin1String(XMLERR_TAGMISMATCH));
return false;
}
@@ -3773,7 +3786,9 @@ bool QXmlSimpleReaderPrivate::processElementEmptyTag()
return false;
}
// ... followed by endElement...
- if (!contentHnd->endElement(uri, lname, tags.pop())) {
+ const bool endElementReturnedFalse = !contentHnd->endElement(uri, lname, tags.top());
+ tags.pop();
+ if (endElementReturnedFalse) {
reportParseError(contentHnd->errorString());
return false;
}
@@ -3800,13 +3815,15 @@ bool QXmlSimpleReaderPrivate::processElementEmptyTag()
return false;
}
// ... followed by endElement
- if (!contentHnd->endElement(QString(), QString(), tags.pop())) {
+ const bool endElementReturnedFalse = !contentHnd->endElement(QString(), QString(), tags.top());
+ tags.pop();
+ if (endElementReturnedFalse) {
reportParseError(contentHnd->errorString());
return false;
}
}
} else {
- tags.pop_back();
+ tags.pop();
namespaceSupport.popContext();
}
return true;
@@ -3820,7 +3837,9 @@ bool QXmlSimpleReaderPrivate::processElementETagBegin2()
const QString &name = QXmlSimpleReaderPrivate::name();
// pop the stack and compare it with the name
- if (tags.pop() != name) {
+ const bool nameIsTagsTop = tags.top() == name;
+ tags.pop();
+ if (!nameIsTagsTop) {
reportParseError(QLatin1String(XMLERR_TAGMISMATCH));
return false;
}
@@ -7839,7 +7858,7 @@ void QXmlSimpleReaderPrivate::init(const QXmlInputSource *i)
externEntities.clear();
entities.clear();
- tags.clear();
+ clear(tags);
doctype.clear();
xmlVersion.clear();