diff options
Diffstat (limited to 'src/xml')
-rw-r--r-- | src/xml/dom/qdom.cpp | 119 | ||||
-rw-r--r-- | src/xml/dom/qdom.h | 8 | ||||
-rw-r--r-- | src/xml/sax/qxml.cpp | 196 | ||||
-rw-r--r-- | src/xml/sax/qxml.h | 14 | ||||
-rw-r--r-- | src/xml/stream/qxmlstream.h | 8 | ||||
-rw-r--r-- | src/xml/xml.pro | 2 |
6 files changed, 183 insertions, 164 deletions
diff --git a/src/xml/dom/qdom.cpp b/src/xml/dom/qdom.cpp index f43d063..2d96273 100644 --- a/src/xml/dom/qdom.cpp +++ b/src/xml/dom/qdom.cpp @@ -1,7 +1,6 @@ /**************************************************************************** ** ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** ** This file is part of the QtXml module of the Qt Toolkit. @@ -21,9 +20,10 @@ ** ensure the GNU Lesser General Public License version 2.1 requirements ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. ** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.1, included in the file LGPL_EXCEPTION.txt in this +** package. ** ** If you have questions regarding the use of this file, please contact ** Nokia at qt-info@nokia.com. @@ -56,6 +56,7 @@ #include <qxml.h> #include <qvariant.h> #include <qmap.h> +#include <qshareddata.h> #include <qdebug.h> #include <stdio.h> @@ -124,7 +125,8 @@ static void qt_split_namespace(QString& prefix, QString& name, const QString& qN class QDomImplementationPrivate { public: - QDomImplementationPrivate() { ref = 1; } + inline QDomImplementationPrivate() {} + QDomImplementationPrivate* clone(); QAtomicInt ref; static QDomImplementation::InvalidDataPolicy invalidDataPolicy; @@ -512,8 +514,8 @@ public: bool setContent(QXmlInputSource *source, QXmlReader *reader, QString *errorMsg, int *errorLine, int *errorColumn); // Attributes - QDomDocumentTypePrivate* doctype() { return type; }; - QDomImplementationPrivate* implementation() { return impl; }; + QDomDocumentTypePrivate* doctype() { return type.data(); }; + QDomImplementationPrivate* implementation() { return impl.data(); }; QDomElementPrivate* documentElement(); // Factories @@ -537,8 +539,8 @@ public: void clear(); // Variables - QDomImplementationPrivate* impl; - QDomDocumentTypePrivate* type; + QExplicitlySharedDataPointer<QDomImplementationPrivate> impl; + QExplicitlySharedDataPointer<QDomDocumentTypePrivate> type; void saveDocument(QTextStream& stream, const int indent, QDomNode::EncodingPolicy encUsed) const; @@ -864,10 +866,7 @@ static QString fixedSystemLiteral(const QString &data, bool *ok) QDomImplementationPrivate* QDomImplementationPrivate::clone() { - QDomImplementationPrivate* p = new QDomImplementationPrivate; - // We are not interested in this node - p->ref.deref(); - return p; + return new QDomImplementationPrivate; } /************************************************************** @@ -1845,8 +1844,7 @@ QDomNodePrivate* QDomNodePrivate::removeChild(QDomNodePrivate* oldChild) oldChild->prev = 0; // We are no longer interested in the old node - if (oldChild) - oldChild->ref.deref(); + oldChild->ref.deref(); return oldChild; } @@ -1939,7 +1937,7 @@ void QDomNodePrivate::setLocation(int lineNumber, int columnNumber) \inmodule QtXml \ingroup xml-tools - \mainclass + Many functions in the DOM return a QDomNode. @@ -2694,7 +2692,7 @@ void QDomNode::save(QTextStream& str, int indent) const If the document contains invalid XML characters or characters that cannot be encoded in the given encoding, the result and behavior is undefined. - \since 4.2 + \since 4.2 */ void QDomNode::save(QTextStream& str, int indent, EncodingPolicy encodingPolicy) const { @@ -3060,7 +3058,7 @@ QDomNamedNodeMapPrivate::~QDomNamedNodeMapPrivate() QDomNamedNodeMapPrivate* QDomNamedNodeMapPrivate::clone(QDomNodePrivate* p) { - QDomNamedNodeMapPrivate* m = new QDomNamedNodeMapPrivate(p); + QScopedPointer<QDomNamedNodeMapPrivate> m(new QDomNamedNodeMapPrivate(p)); m->readonly = readonly; m->appendToParent = appendToParent; @@ -3073,7 +3071,7 @@ QDomNamedNodeMapPrivate* QDomNamedNodeMapPrivate::clone(QDomNodePrivate* p) // we are no longer interested in ownership m->ref.deref(); - return m; + return m.take(); } void QDomNamedNodeMapPrivate::clearMap() @@ -3499,13 +3497,18 @@ QDomDocumentTypePrivate::~QDomDocumentTypePrivate() void QDomDocumentTypePrivate::init() { entities = new QDomNamedNodeMapPrivate(this); - notations = new QDomNamedNodeMapPrivate(this); - publicId.clear(); - systemId.clear(); - internalSubset.clear(); - - entities->setAppendToParent(true); - notations->setAppendToParent(true); + QT_TRY { + notations = new QDomNamedNodeMapPrivate(this); + publicId.clear(); + systemId.clear(); + internalSubset.clear(); + + entities->setAppendToParent(true); + notations->setAppendToParent(true); + } QT_CATCH(...) { + delete entities; + QT_RETHROW; + } } QDomNodePrivate* QDomDocumentTypePrivate::cloneNode(bool deep) @@ -4355,7 +4358,7 @@ bool QDomAttr::specified() const QDomElement QDomAttr::ownerElement() const { Q_ASSERT(impl->parent()); - if (!impl || !impl->parent()->isElement()) + if (!impl->parent()->isElement()) return QDomElement(); return QDomElement((QDomElementPrivate*)(impl->parent())); } @@ -4589,7 +4592,7 @@ void QDomElementPrivate::save(QTextStream& s, int depth, int indent) const qName = prefix + QLatin1Char(':') + name; nsDecl = QLatin1String(" xmlns:") + prefix; } - nsDecl += QLatin1String("=\"") + encodeText(namespaceURI, s) + QLatin1String("\""); + nsDecl += QLatin1String("=\"") + encodeText(namespaceURI, s) + QLatin1Char('\"'); } s << '<' << qName << nsDecl; @@ -4597,9 +4600,9 @@ void QDomElementPrivate::save(QTextStream& s, int depth, int indent) const /* Write out attributes. */ if (!m_attr->map.isEmpty()) { - s << ' '; QHash<QString, QDomNodePrivate *>::const_iterator it = m_attr->map.constBegin(); for (; it != m_attr->map.constEnd(); ++it) { + s << ' '; if (it.value()->namespaceURI.isNull()) { s << it.value()->name << "=\"" << encodeText(it.value()->value, s, true, true) << '\"'; } else { @@ -4622,7 +4625,6 @@ void QDomElementPrivate::save(QTextStream& s, int depth, int indent) const outputtedPrefixes.insert(it.value()->prefix); } } - s << ' '; } } @@ -6146,20 +6148,22 @@ void QDomProcessingInstruction::setData(const QString& d) QDomDocumentPrivate::QDomDocumentPrivate() : QDomNodePrivate(0), + impl(new QDomImplementationPrivate), nodeListTime(1) { - impl = new QDomImplementationPrivate; type = new QDomDocumentTypePrivate(this, this); + type->ref.deref(); name = QLatin1String("#document"); } QDomDocumentPrivate::QDomDocumentPrivate(const QString& aname) : QDomNodePrivate(0), + impl(new QDomImplementationPrivate), nodeListTime(1) { - impl = new QDomImplementationPrivate; type = new QDomDocumentTypePrivate(this, this); + type->ref.deref(); type->name = aname; name = QLatin1String("#document"); @@ -6167,14 +6171,14 @@ QDomDocumentPrivate::QDomDocumentPrivate(const QString& aname) QDomDocumentPrivate::QDomDocumentPrivate(QDomDocumentTypePrivate* dt) : QDomNodePrivate(0), + impl(new QDomImplementationPrivate), nodeListTime(1) { - impl = new QDomImplementationPrivate; if (dt != 0) { type = dt; - type->ref.ref(); } else { type = new QDomDocumentTypePrivate(this, this); + type->ref.deref(); } name = QLatin1String("#document"); @@ -6182,33 +6186,21 @@ QDomDocumentPrivate::QDomDocumentPrivate(QDomDocumentTypePrivate* dt) QDomDocumentPrivate::QDomDocumentPrivate(QDomDocumentPrivate* n, bool deep) : QDomNodePrivate(n, deep), + impl(n->impl->clone()), nodeListTime(1) { - impl = n->impl->clone(); - // Reference count is down to 0, so we set it to 1 here. - impl->ref.ref(); - type = (QDomDocumentTypePrivate*)n->type->cloneNode(); + type = static_cast<QDomDocumentTypePrivate*>(n->type->cloneNode()); type->setParent(this); - // Reference count is down to 0, so we set it to 1 here. - type->ref.ref(); } QDomDocumentPrivate::~QDomDocumentPrivate() { - if (!impl->ref.deref()) - delete impl; - if (!type->ref.deref()) - delete type; } void QDomDocumentPrivate::clear() { - if (!impl->ref.deref()) - delete impl; - if (!type->ref.deref()) - delete type; - impl = 0; - type = 0; + impl.reset(); + type.reset(); QDomNodePrivate::clear(); } @@ -6231,6 +6223,7 @@ bool QDomDocumentPrivate::setContent(QXmlInputSource *source, QXmlReader *reader clear(); impl = new QDomImplementationPrivate; type = new QDomDocumentTypePrivate(this, this); + type->ref.deref(); bool namespaceProcessing = reader->feature(QLatin1String("http://xml.org/sax/features/namespaces")) && !reader->feature(QLatin1String("http://xml.org/sax/features/namespace-prefixes")); @@ -6524,7 +6517,7 @@ void QDomDocumentPrivate::saveDocument(QTextStream& s, const int indent, QDomNod \brief The QDomDocument class represents an XML document. \inmodule QtXml - \mainclass + \ingroup xml-tools The QDomDocument class represents the entire XML document. @@ -7413,7 +7406,9 @@ bool QDomHandler::startElement(const QString& nsURI, const QString&, const QStri } else { n = doc->createElement(qName); } - n->setLocation(locator->lineNumber(), locator->columnNumber()); + + if (n) + n->setLocation(locator->lineNumber(), locator->columnNumber()); node->appendChild(n); node = n; @@ -7433,7 +7428,7 @@ bool QDomHandler::startElement(const QString& nsURI, const QString&, const QStri bool QDomHandler::endElement(const QString&, const QString&, const QString&) { - if (node == doc) + if (!node || node == doc) return false; node = node->parent(); @@ -7446,20 +7441,22 @@ bool QDomHandler::characters(const QString& ch) if (node == doc) return false; - QDomNodePrivate *n; + QScopedPointer<QDomNodePrivate> n; if (cdata) { - n = doc->createCDATASection(ch); + n.reset(doc->createCDATASection(ch)); } else if (!entityName.isEmpty()) { - QDomEntityPrivate* e = new QDomEntityPrivate(doc, 0, entityName, - QString(), QString(), QString()); + QScopedPointer<QDomEntityPrivate> e(new QDomEntityPrivate(doc, 0, entityName, + QString(), QString(), QString())); e->value = ch; - doc->doctype()->appendChild(e); - n = doc->createEntityReference(entityName); + doc->doctype()->appendChild(e.data()); + e.take(); + n.reset(doc->createEntityReference(entityName)); } else { - n = doc->createTextNode(ch); + n.reset(doc->createTextNode(ch)); } n->setLocation(locator->lineNumber(), locator->columnNumber()); - node->appendChild(n); + node->appendChild(n.data()); + n.take(); return true; } diff --git a/src/xml/dom/qdom.h b/src/xml/dom/qdom.h index 406e903..ca97e9d 100644 --- a/src/xml/dom/qdom.h +++ b/src/xml/dom/qdom.h @@ -1,7 +1,6 @@ /**************************************************************************** ** ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** ** This file is part of the QtXml module of the Qt Toolkit. @@ -21,9 +20,10 @@ ** ensure the GNU Lesser General Public License version 2.1 requirements ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. ** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.1, included in the file LGPL_EXCEPTION.txt in this +** package. ** ** If you have questions regarding the use of this file, please contact ** Nokia at qt-info@nokia.com. diff --git a/src/xml/sax/qxml.cpp b/src/xml/sax/qxml.cpp index ffbed27..bb4b5c5 100644 --- a/src/xml/sax/qxml.cpp +++ b/src/xml/sax/qxml.cpp @@ -1,7 +1,6 @@ /**************************************************************************** ** ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** ** This file is part of the QtXml module of the Qt Toolkit. @@ -21,9 +20,10 @@ ** ensure the GNU Lesser General Public License version 2.1 requirements ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. ** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.1, included in the file LGPL_EXCEPTION.txt in this +** package. ** ** If you have questions regarding the use of this file, please contact ** Nokia at qt-info@nokia.com. @@ -244,6 +244,16 @@ public: class QXmlParseExceptionPrivate { public: + QXmlParseExceptionPrivate() + : column(-1), line(-1) + { + } + QXmlParseExceptionPrivate(const QXmlParseExceptionPrivate &other) + : msg(other.msg), column(other.column), line(other.line), + pub(other.pub), sys(other.sys) + { + } + QString msg; int column; int line; @@ -262,10 +272,11 @@ class QXmlDefaultHandlerPrivate class QXmlSimpleReaderPrivate { +public: + ~QXmlSimpleReaderPrivate(); private: // functions - QXmlSimpleReaderPrivate(); - ~QXmlSimpleReaderPrivate(); + QXmlSimpleReaderPrivate(QXmlSimpleReader *reader); void initIncrementalParsing(); // used to determine if elements are correctly nested @@ -302,7 +313,9 @@ private: // used for parsing of entity references struct XmlRef { - XmlRef(const QString &_name = QString(), const QString &_value = QString()) + XmlRef() + : index(0) {} + XmlRef(const QString &_name, const QString &_value) : name(_name), value(_value), index(0) {} bool isEmpty() const { return index == value.length(); } QChar next() { return value.at(index++); } @@ -348,7 +361,7 @@ private: bool contentCharDataRead; // helper classes - QXmlLocator *locator; + QScopedPointer<QXmlLocator> locator; QXmlNamespaceSupport namespaceSupport; // error string @@ -543,8 +556,8 @@ private: QXmlParseException::QXmlParseException(const QString& name, int c, int l, const QString& p, const QString& s) + : d(new QXmlParseExceptionPrivate) { - d = new QXmlParseExceptionPrivate; d->msg = name; d->column = c; d->line = l; @@ -553,11 +566,19 @@ QXmlParseException::QXmlParseException(const QString& name, int c, int l, } /*! + Creates a copy of \a other. +*/ +QXmlParseException::QXmlParseException(const QXmlParseException& other) : + d(new QXmlParseExceptionPrivate(*other.d)) +{ + +} + +/*! Destroys the QXmlParseException. */ QXmlParseException::~QXmlParseException() { - delete d; } /*! @@ -926,8 +947,9 @@ void QXmlNamespaceSupport::popContext() */ void QXmlNamespaceSupport::reset() { + QXmlNamespaceSupportPrivate *newD = new QXmlNamespaceSupportPrivate; delete d; - d = new QXmlNamespaceSupportPrivate; + d = newD; } @@ -1258,18 +1280,23 @@ void QXmlInputSource::init() { d = new QXmlInputSourcePrivate; - d->inputDevice = 0; - d->inputStream = 0; + QT_TRY { + d->inputDevice = 0; + d->inputStream = 0; - setData(QString()); + setData(QString()); #ifndef QT_NO_TEXTCODEC - d->encMapper = 0; + d->encMapper = 0; #endif - d->nextReturnedEndOfData = true; // first call to next() will call fetchData() + d->nextReturnedEndOfData = true; // first call to next() will call fetchData() - d->encodingDeclBytes.clear(); - d->encodingDeclChars.clear(); - d->lookingForEncodingDecl = true; + d->encodingDeclBytes.clear(); + d->encodingDeclChars.clear(); + d->lookingForEncodingDecl = true; + } QT_CATCH(...) { + delete(d); + QT_RETHROW; + } } /*! @@ -2403,7 +2430,7 @@ events are reported. /*! \reimp - Does nothing. + This reimplementation does nothing. */ void QXmlDefaultHandler::setDocumentLocator(QXmlLocator*) { @@ -2412,7 +2439,7 @@ void QXmlDefaultHandler::setDocumentLocator(QXmlLocator*) /*! \reimp - Does nothing. + This reimplementation does nothing. */ bool QXmlDefaultHandler::startDocument() { @@ -2422,7 +2449,7 @@ bool QXmlDefaultHandler::startDocument() /*! \reimp - Does nothing. + This reimplementation does nothing. */ bool QXmlDefaultHandler::endDocument() { @@ -2432,7 +2459,7 @@ bool QXmlDefaultHandler::endDocument() /*! \reimp - Does nothing. + This reimplementation does nothing. */ bool QXmlDefaultHandler::startPrefixMapping(const QString&, const QString&) { @@ -2442,7 +2469,7 @@ bool QXmlDefaultHandler::startPrefixMapping(const QString&, const QString&) /*! \reimp - Does nothing. + This reimplementation does nothing. */ bool QXmlDefaultHandler::endPrefixMapping(const QString&) { @@ -2452,7 +2479,7 @@ bool QXmlDefaultHandler::endPrefixMapping(const QString&) /*! \reimp - Does nothing. + This reimplementation does nothing. */ bool QXmlDefaultHandler::startElement(const QString&, const QString&, const QString&, const QXmlAttributes&) @@ -2463,7 +2490,7 @@ bool QXmlDefaultHandler::startElement(const QString&, const QString&, /*! \reimp - Does nothing. + This reimplementation does nothing. */ bool QXmlDefaultHandler::endElement(const QString&, const QString&, const QString&) @@ -2474,7 +2501,7 @@ bool QXmlDefaultHandler::endElement(const QString&, const QString&, /*! \reimp - Does nothing. + This reimplementation does nothing. */ bool QXmlDefaultHandler::characters(const QString&) { @@ -2484,7 +2511,7 @@ bool QXmlDefaultHandler::characters(const QString&) /*! \reimp - Does nothing. + This reimplementation does nothing. */ bool QXmlDefaultHandler::ignorableWhitespace(const QString&) { @@ -2494,7 +2521,7 @@ bool QXmlDefaultHandler::ignorableWhitespace(const QString&) /*! \reimp - Does nothing. + This reimplementation does nothing. */ bool QXmlDefaultHandler::processingInstruction(const QString&, const QString&) @@ -2505,7 +2532,7 @@ bool QXmlDefaultHandler::processingInstruction(const QString&, /*! \reimp - Does nothing. + This reimplementation does nothing. */ bool QXmlDefaultHandler::skippedEntity(const QString&) { @@ -2515,7 +2542,7 @@ bool QXmlDefaultHandler::skippedEntity(const QString&) /*! \reimp - Does nothing. + This reimplementation does nothing. */ bool QXmlDefaultHandler::warning(const QXmlParseException&) { @@ -2525,7 +2552,7 @@ bool QXmlDefaultHandler::warning(const QXmlParseException&) /*! \reimp - Does nothing. + This reimplementation does nothing. */ bool QXmlDefaultHandler::error(const QXmlParseException&) { @@ -2535,7 +2562,7 @@ bool QXmlDefaultHandler::error(const QXmlParseException&) /*! \reimp - Does nothing. + This reimplementation does nothing. */ bool QXmlDefaultHandler::fatalError(const QXmlParseException&) { @@ -2545,7 +2572,7 @@ bool QXmlDefaultHandler::fatalError(const QXmlParseException&) /*! \reimp - Does nothing. + This reimplementation does nothing. */ bool QXmlDefaultHandler::notationDecl(const QString&, const QString&, const QString&) @@ -2556,7 +2583,7 @@ bool QXmlDefaultHandler::notationDecl(const QString&, const QString&, /*! \reimp - Does nothing. + This reimplementation does nothing. */ bool QXmlDefaultHandler::unparsedEntityDecl(const QString&, const QString&, const QString&, const QString&) @@ -2590,7 +2617,7 @@ QString QXmlDefaultHandler::errorString() const /*! \reimp - Does nothing. + This reimplementation does nothing. */ bool QXmlDefaultHandler::startDTD(const QString&, const QString&, const QString&) { @@ -2600,7 +2627,7 @@ bool QXmlDefaultHandler::startDTD(const QString&, const QString&, const QString& /*! \reimp - Does nothing. + This reimplementation does nothing. */ bool QXmlDefaultHandler::endDTD() { @@ -2610,7 +2637,7 @@ bool QXmlDefaultHandler::endDTD() /*! \reimp - Does nothing. + This reimplementation does nothing. */ bool QXmlDefaultHandler::startEntity(const QString&) { @@ -2620,7 +2647,7 @@ bool QXmlDefaultHandler::startEntity(const QString&) /*! \reimp - Does nothing. + This reimplementation does nothing. */ bool QXmlDefaultHandler::endEntity(const QString&) { @@ -2630,7 +2657,7 @@ bool QXmlDefaultHandler::endEntity(const QString&) /*! \reimp - Does nothing. + This reimplementation does nothing. */ bool QXmlDefaultHandler::startCDATA() { @@ -2640,7 +2667,7 @@ bool QXmlDefaultHandler::startCDATA() /*! \reimp - Does nothing. + This reimplementation does nothing. */ bool QXmlDefaultHandler::endCDATA() { @@ -2650,7 +2677,7 @@ bool QXmlDefaultHandler::endCDATA() /*! \reimp - Does nothing. + This reimplementation does nothing. */ bool QXmlDefaultHandler::comment(const QString&) { @@ -2660,7 +2687,7 @@ bool QXmlDefaultHandler::comment(const QString&) /*! \reimp - Does nothing. + This reimplementation does nothing. */ bool QXmlDefaultHandler::attributeDecl(const QString&, const QString&, const QString&, const QString&, const QString&) { @@ -2670,7 +2697,7 @@ bool QXmlDefaultHandler::attributeDecl(const QString&, const QString&, const QSt /*! \reimp - Does nothing. + This reimplementation does nothing. */ bool QXmlDefaultHandler::internalEntityDecl(const QString&, const QString&) { @@ -2680,7 +2707,7 @@ bool QXmlDefaultHandler::internalEntityDecl(const QString&, const QString&) /*! \reimp - Does nothing. + This reimplementation does nothing. */ bool QXmlDefaultHandler::externalEntityDecl(const QString&, const QString&, const QString&) { @@ -2713,9 +2740,24 @@ inline void QXmlSimpleReaderPrivate::refClear() refValueLen = 0; refArrayPos = 0; } -QXmlSimpleReaderPrivate::QXmlSimpleReaderPrivate() +QXmlSimpleReaderPrivate::QXmlSimpleReaderPrivate(QXmlSimpleReader *reader) { + q_ptr = reader; parseStack = 0; + + locator.reset(new QXmlSimpleReaderLocator(reader)); + entityRes = 0; + dtdHnd = 0; + contentHnd = 0; + errorHnd = 0; + lexicalHnd = 0; + declHnd = 0; + + // default feature settings + useNamespaces = true; + useNamespacePrefixes = false; + reportWhitespaceCharData = true; + reportEntities = false; } QXmlSimpleReaderPrivate::~QXmlSimpleReaderPrivate() @@ -2725,8 +2767,10 @@ QXmlSimpleReaderPrivate::~QXmlSimpleReaderPrivate() void QXmlSimpleReaderPrivate::initIncrementalParsing() { - delete parseStack; - parseStack = new QStack<ParseState>; + if(parseStack) + parseStack->clear(); + else + parseStack = new QStack<ParseState>; } /********************************************* @@ -2968,7 +3012,7 @@ void QXmlSimpleReaderPrivate::initIncrementalParsing() \inmodule QtXml \ingroup xml-tools - \mainclass + This XML reader is suitable for a wide range of applications. It is able to parse well-formed XML and can report the namespaces of @@ -3012,19 +3056,13 @@ void QXmlSimpleReaderPrivate::initIncrementalParsing() parse() to work incrementally, and making subsequent calls to the parseContinue() function, until all the data has been processed. - A common way to perform incremental parsing is to connect the - \c readyRead() signal of the input source to a slot, and handle the - incoming data there. For example, the following code shows how a - parser for \l{http://web.resource.org/rss/1.0/}{RSS feeds} can be - used to incrementally parse data that it receives from a QHttp - object: - - \snippet doc/src/snippets/xml/rsslisting/rsslisting.cpp 1 - + A common way to perform incremental parsing is to connect the \c + readyRead() signal of a \l{QNetworkReply} {network reply} a slot, + and handle the incoming data there. See QNetworkAccessManager. + Aspects of the parsing behavior can be adapted using setFeature() - and setProperty(). For example, the following code could be used - to enable reporting of namespace prefixes to the content handler: - + and setProperty(). + QXmlSimpleReader is not reentrant. If you want to use the class in threaded code, lock the code using QXmlSimpleReader with a locking mechanism, such as a QMutex. @@ -3099,25 +3137,8 @@ static NameChar determineNameChar(QChar ch) */ QXmlSimpleReader::QXmlSimpleReader() + : d_ptr(new QXmlSimpleReaderPrivate(this)) { - d_ptr = new QXmlSimpleReaderPrivate(); - Q_D(QXmlSimpleReader); - d->q_ptr = this; - - d->locator = new QXmlSimpleReaderLocator(this); - - d->entityRes = 0; - d->dtdHnd = 0; - d->contentHnd = 0; - d->errorHnd = 0; - d->lexicalHnd = 0; - d->declHnd = 0; - - // default feature settings - d->useNamespaces = true; - d->useNamespacePrefixes = false; - d->reportWhitespaceCharData = true; - d->reportEntities = false; } /*! @@ -3125,9 +3146,6 @@ QXmlSimpleReader::QXmlSimpleReader() */ QXmlSimpleReader::~QXmlSimpleReader() { - Q_D(QXmlSimpleReader); - delete d->locator; - delete d; } /*! @@ -3410,7 +3428,7 @@ bool QXmlSimpleReader::parse(const QXmlInputSource *input, bool incremental) // call the handler if (d->contentHnd) { - d->contentHnd->setDocumentLocator(d->locator); + d->contentHnd->setDocumentLocator(d->locator.data()); if (!d->contentHnd->startDocument()) { d->reportParseError(d->contentHnd->errorString()); d->tags.clear(); @@ -5464,7 +5482,7 @@ bool QXmlSimpleReaderPrivate::parsePEReference() if (skipIt) { if (contentHnd) { - if (!contentHnd->skippedEntity(QString::fromLatin1("%") + ref())) { + if (!contentHnd->skippedEntity(QLatin1Char('%') + ref())) { reportParseError(contentHnd->errorString()); return false; } @@ -5476,7 +5494,7 @@ bool QXmlSimpleReaderPrivate::parsePEReference() return false; } else if (parsePEReference_context == InDTD) { // Included as PE - if (!insertXmlRef(QString::fromLatin1(" ")+xmlRefString+QString::fromLatin1(" "), ref(), false)) + if (!insertXmlRef(QLatin1Char(' ') + xmlRefString + QLatin1Char(' '), ref(), false)) return false; } } @@ -6728,7 +6746,7 @@ bool QXmlSimpleReaderPrivate::parseEntityDecl() if ( !entityExist(name())) { parameterEntities.insert(name(), string()); if (declHnd) { - if (!declHnd->internalEntityDecl(QString::fromLatin1("%")+name(), string())) { + if (!declHnd->internalEntityDecl(QLatin1Char('%') + name(), string())) { reportParseError(declHnd->errorString()); return false; } @@ -6740,7 +6758,7 @@ bool QXmlSimpleReaderPrivate::parseEntityDecl() if ( !entityExist(name())) { externParameterEntities.insert(name(), QXmlSimpleReaderPrivate::ExternParameterEntity(publicId, systemId)); if (declHnd) { - if (!declHnd->externalEntityDecl(QString::fromLatin1("%")+name(), publicId, systemId)) { + if (!declHnd->externalEntityDecl(QLatin1Char('%') + name(), publicId, systemId)) { reportParseError(declHnd->errorString()); return false; } @@ -7864,8 +7882,8 @@ bool QXmlSimpleReaderPrivate::insertXmlRef(const QString &data, const QString &n { if (inLiteral) { QString tmp = data; - xmlRefStack.push(XmlRef(name, tmp.replace(QLatin1String("\""), - QLatin1String(""")).replace(QLatin1String("'"), QLatin1String("'")))); + xmlRefStack.push(XmlRef(name, tmp.replace(QLatin1Char('\"'), + QLatin1String(""")).replace(QLatin1Char('\''), QLatin1String("'")))); } else { xmlRefStack.push(XmlRef(name, data)); } diff --git a/src/xml/sax/qxml.h b/src/xml/sax/qxml.h index e86f32d..fa19e32 100644 --- a/src/xml/sax/qxml.h +++ b/src/xml/sax/qxml.h @@ -1,7 +1,6 @@ /**************************************************************************** ** ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** ** This file is part of the QtXml module of the Qt Toolkit. @@ -21,9 +20,10 @@ ** ensure the GNU Lesser General Public License version 2.1 requirements ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. ** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.1, included in the file LGPL_EXCEPTION.txt in this +** package. ** ** If you have questions regarding the use of this file, please contact ** Nokia at qt-info@nokia.com. @@ -47,6 +47,7 @@ #include <QtCore/qstring.h> #include <QtCore/qstringlist.h> #include <QtCore/qlist.h> +#include <QtCore/qscopedpointer.h> QT_BEGIN_HEADER @@ -193,6 +194,7 @@ class Q_XML_EXPORT QXmlParseException public: explicit QXmlParseException(const QString &name = QString(), int c = -1, int l = -1, const QString &p = QString(), const QString &s = QString()); + QXmlParseException(const QXmlParseException &other); ~QXmlParseException(); int columnNumber() const; @@ -202,7 +204,7 @@ public: QString message() const; private: - QXmlParseExceptionPrivate *d; + QScopedPointer<QXmlParseExceptionPrivate> d; }; @@ -271,7 +273,7 @@ public: private: Q_DISABLE_COPY(QXmlSimpleReader) Q_DECLARE_PRIVATE(QXmlSimpleReader) - QXmlSimpleReaderPrivate* d_ptr; + QScopedPointer<QXmlSimpleReaderPrivate> d_ptr; friend class QXmlSimpleReaderLocator; }; diff --git a/src/xml/stream/qxmlstream.h b/src/xml/stream/qxmlstream.h index 89f8a5c8..64dced6 100644 --- a/src/xml/stream/qxmlstream.h +++ b/src/xml/stream/qxmlstream.h @@ -1,7 +1,6 @@ /**************************************************************************** ** ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** ** This file is part of the QtXml module of the Qt Toolkit. @@ -21,9 +20,10 @@ ** ensure the GNU Lesser General Public License version 2.1 requirements ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. ** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.1, included in the file LGPL_EXCEPTION.txt in this +** package. ** ** If you have questions regarding the use of this file, please contact ** Nokia at qt-info@nokia.com. diff --git a/src/xml/xml.pro b/src/xml/xml.pro index 0c7133c..8d1bf68 100644 --- a/src/xml/xml.pro +++ b/src/xml/xml.pro @@ -18,3 +18,5 @@ win32-borland { include(dom/dom.pri) include(sax/sax.pri) include(stream/stream.pri) + +symbian:TARGET.UID3=0x2001B2E0 |