Ignore:
Timestamp:
Feb 11, 2010, 11:19:06 PM (15 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.6.1 sources.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/xml/dom/qdom.cpp

    r2 r561  
    22**
    33** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
    4 ** Contact: Qt Software Information (qt-info@nokia.com)
     4** All rights reserved.
     5** Contact: Nokia Corporation (qt-info@nokia.com)
    56**
    67** This file is part of the QtXml module of the Qt Toolkit.
     
    2122** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    2223**
    23 ** In addition, as a special exception, Nokia gives you certain
    24 ** additional rights. These rights are described in the Nokia Qt LGPL
    25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
    26 ** package.
     24** In addition, as a special exception, Nokia gives you certain additional
     25** rights.  These rights are described in the Nokia Qt LGPL Exception
     26** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
    2727**
    2828** GNU General Public License Usage
     
    3434** met: http://www.gnu.org/copyleft/gpl.html.
    3535**
    36 ** If you are unsure which license is appropriate for your use, please
    37 ** contact the sales department at qt-sales@nokia.com.
     36** If you have questions regarding the use of this file, please contact
     37** Nokia at qt-info@nokia.com.
    3838** $QT_END_LICENSE$
    3939**
     
    5757#include <qvariant.h>
    5858#include <qmap.h>
     59#include <qshareddata.h>
    5960#include <qdebug.h>
    6061#include <stdio.h>
     
    125126{
    126127public:
    127     QDomImplementationPrivate() { ref = 1; }
     128    inline QDomImplementationPrivate() {}
     129
    128130    QDomImplementationPrivate* clone();
    129131    QAtomicInt ref;
     
    513515
    514516    // Attributes
    515     QDomDocumentTypePrivate* doctype() { return type; };
    516     QDomImplementationPrivate* implementation() { return impl; };
     517    QDomDocumentTypePrivate* doctype() { return type.data(); }
     518    QDomImplementationPrivate* implementation() { return impl.data(); }
    517519    QDomElementPrivate* documentElement();
    518520
     
    538540
    539541    // Variables
    540     QDomImplementationPrivate* impl;
    541     QDomDocumentTypePrivate* type;
     542    QExplicitlySharedDataPointer<QDomImplementationPrivate> impl;
     543    QExplicitlySharedDataPointer<QDomDocumentTypePrivate> type;
    542544
    543545    void saveDocument(QTextStream& stream, const int indent, QDomNode::EncodingPolicy encUsed) const;
     
    865867QDomImplementationPrivate* QDomImplementationPrivate::clone()
    866868{
    867     QDomImplementationPrivate* p = new QDomImplementationPrivate;
    868     // We are not interested in this node
    869     p->ref.deref();
    870     return p;
     869    return new QDomImplementationPrivate;
    871870}
    872871
     
    18461845
    18471846    // We are no longer interested in the old node
    1848     if (oldChild)
    1849         oldChild->ref.deref();
     1847    oldChild->ref.deref();
    18501848
    18511849    return oldChild;
     
    19401938    \inmodule QtXml
    19411939    \ingroup xml-tools
    1942     \mainclass
     1940
    19431941
    19441942    Many functions in the DOM return a QDomNode.
     
    26952693    encoded in the given encoding, the result and behavior is undefined.
    26962694
    2697  \since 4.2
     2695    \since 4.2
    26982696 */
    26992697void QDomNode::save(QTextStream& str, int indent, EncodingPolicy encodingPolicy) const
     
    30613059QDomNamedNodeMapPrivate* QDomNamedNodeMapPrivate::clone(QDomNodePrivate* p)
    30623060{
    3063     QDomNamedNodeMapPrivate* m = new QDomNamedNodeMapPrivate(p);
     3061    QScopedPointer<QDomNamedNodeMapPrivate> m(new QDomNamedNodeMapPrivate(p));
    30643062    m->readonly = readonly;
    30653063    m->appendToParent = appendToParent;
     
    30743072    // we are no longer interested in ownership
    30753073    m->ref.deref();
    3076     return m;
     3074    return m.take();
    30773075}
    30783076
     
    35003498{
    35013499    entities = new QDomNamedNodeMapPrivate(this);
    3502     notations = new QDomNamedNodeMapPrivate(this);
    3503     publicId.clear();
    3504     systemId.clear();
    3505     internalSubset.clear();
    3506 
    3507     entities->setAppendToParent(true);
    3508     notations->setAppendToParent(true);
     3500    QT_TRY {
     3501        notations = new QDomNamedNodeMapPrivate(this);
     3502        publicId.clear();
     3503        systemId.clear();
     3504        internalSubset.clear();
     3505
     3506        entities->setAppendToParent(true);
     3507        notations->setAppendToParent(true);
     3508    } QT_CATCH(...) {
     3509        delete entities;
     3510        QT_RETHROW;
     3511    }
    35093512}
    35103513
     
    43564359{
    43574360    Q_ASSERT(impl->parent());
    4358     if (!impl || !impl->parent()->isElement())
     4361    if (!impl->parent()->isElement())
    43594362        return QDomElement();
    43604363    return QDomElement((QDomElementPrivate*)(impl->parent()));
     
    45904593            nsDecl = QLatin1String(" xmlns:") + prefix;
    45914594        }
    4592         nsDecl += QLatin1String("=\"") + encodeText(namespaceURI, s) + QLatin1String("\"");
     4595        nsDecl += QLatin1String("=\"") + encodeText(namespaceURI, s) + QLatin1Char('\"');
    45934596    }
    45944597    s << '<' << qName << nsDecl;
     
    45984601    /* Write out attributes. */
    45994602    if (!m_attr->map.isEmpty()) {
    4600         s << ' ';
    46014603        QHash<QString, QDomNodePrivate *>::const_iterator it = m_attr->map.constBegin();
    46024604        for (; it != m_attr->map.constEnd(); ++it) {
     4605            s << ' ';
    46034606            if (it.value()->namespaceURI.isNull()) {
    46044607                s << it.value()->name << "=\"" << encodeText(it.value()->value, s, true, true) << '\"';
     
    46234626                }
    46244627            }
    4625             s << ' ';
    46264628        }
    46274629    }
     
    61476149QDomDocumentPrivate::QDomDocumentPrivate()
    61486150    : QDomNodePrivate(0),
     6151      impl(new QDomImplementationPrivate),
    61496152      nodeListTime(1)
    61506153{
    6151     impl = new QDomImplementationPrivate;
    61526154    type = new QDomDocumentTypePrivate(this, this);
     6155    type->ref.deref();
    61536156
    61546157    name = QLatin1String("#document");
     
    61576160QDomDocumentPrivate::QDomDocumentPrivate(const QString& aname)
    61586161    : QDomNodePrivate(0),
     6162      impl(new QDomImplementationPrivate),
    61596163      nodeListTime(1)
    61606164{
    6161     impl = new QDomImplementationPrivate;
    61626165    type = new QDomDocumentTypePrivate(this, this);
     6166    type->ref.deref();
    61636167    type->name = aname;
    61646168
     
    61686172QDomDocumentPrivate::QDomDocumentPrivate(QDomDocumentTypePrivate* dt)
    61696173    : QDomNodePrivate(0),
     6174      impl(new QDomImplementationPrivate),
    61706175      nodeListTime(1)
    61716176{
    6172     impl = new QDomImplementationPrivate;
    61736177    if (dt != 0) {
    61746178        type = dt;
    6175         type->ref.ref();
    61766179    } else {
    61776180        type = new QDomDocumentTypePrivate(this, this);
     6181        type->ref.deref();
    61786182    }
    61796183
     
    61836187QDomDocumentPrivate::QDomDocumentPrivate(QDomDocumentPrivate* n, bool deep)
    61846188    : QDomNodePrivate(n, deep),
     6189      impl(n->impl->clone()),
    61856190      nodeListTime(1)
    61866191{
    6187     impl = n->impl->clone();
    6188     // Reference count is down to 0, so we set it to 1 here.
    6189     impl->ref.ref();
    6190     type = (QDomDocumentTypePrivate*)n->type->cloneNode();
     6192    type = static_cast<QDomDocumentTypePrivate*>(n->type->cloneNode());
    61916193    type->setParent(this);
    6192     // Reference count is down to 0, so we set it to 1 here.
    6193     type->ref.ref();
    61946194}
    61956195
    61966196QDomDocumentPrivate::~QDomDocumentPrivate()
    61976197{
    6198     if (!impl->ref.deref())
    6199         delete impl;
    6200     if (!type->ref.deref())
    6201         delete type;
    62026198}
    62036199
    62046200void QDomDocumentPrivate::clear()
    62056201{
    6206     if (!impl->ref.deref())
    6207         delete impl;
    6208     if (!type->ref.deref())
    6209         delete type;
    6210     impl = 0;
    6211     type = 0;
     6202    impl.reset();
     6203    type.reset();
    62126204    QDomNodePrivate::clear();
    62136205}
     
    62326224    impl = new QDomImplementationPrivate;
    62336225    type = new QDomDocumentTypePrivate(this, this);
     6226    type->ref.deref();
    62346227
    62356228    bool namespaceProcessing = reader->feature(QLatin1String("http://xml.org/sax/features/namespaces"))
     
    64466439        const QDomNodePrivate* n = first;
    64476440
     6441        QTextCodec *codec = 0;
     6442
    64486443        if (n && n->isProcessingInstruction() && n->nodeName() == QLatin1String("xml")) {
    64496444            // we have an XML declaration
     
    64526447            encoding.indexIn(data);
    64536448            QString enc = encoding.cap(3);
    6454             if (enc.isEmpty()) {
     6449            if (enc.isEmpty())
    64556450                enc = encoding.cap(5);
    6456             }
    6457             if (enc.isEmpty())
    6458                 s.setCodec(QTextCodec::codecForName("UTF-8"));
    6459             else
    6460                 s.setCodec(QTextCodec::codecForName(enc.toLatin1().data()));
    6461         } else {
    6462             s.setCodec(QTextCodec::codecForName("UTF-8"));
     6451            if (!enc.isEmpty())
     6452                codec = QTextCodec::codecForName(enc.toLatin1().data());
    64636453        }
     6454        if (!codec)
     6455            codec = QTextCodec::codecForName("UTF-8");
     6456        if (codec)
     6457            s.setCodec(codec);
    64646458#endif
    64656459        bool doc = false;
     
    65256519
    65266520    \inmodule QtXml
    6527     \mainclass
     6521
    65286522    \ingroup xml-tools
    65296523
     
    73807374
    73817375QDomHandler::QDomHandler(QDomDocumentPrivate* adoc, bool namespaceProcessing)
    7382 {
    7383     doc = adoc;
    7384     node = doc;
    7385     cdata = false;
    7386     nsProcessing = namespaceProcessing;
     7376    : errorLine(0), errorColumn(0), doc(adoc), node(adoc), cdata(false),
     7377        nsProcessing(namespaceProcessing), locator(0)
     7378{
    73877379}
    73887380
     
    74167408        n = doc->createElement(qName);
    74177409    }
    7418     n->setLocation(locator->lineNumber(), locator->columnNumber());
     7410
     7411    if (n)
     7412        n->setLocation(locator->lineNumber(), locator->columnNumber());
    74197413
    74207414    node->appendChild(n);
     
    74367430bool QDomHandler::endElement(const QString&, const QString&, const QString&)
    74377431{
    7438     if (node == doc)
     7432    if (!node || node == doc)
    74397433        return false;
    74407434    node = node->parent();
     
    74497443        return false;
    74507444
    7451     QDomNodePrivate *n;
     7445    QScopedPointer<QDomNodePrivate> n;
    74527446    if (cdata) {
    7453         n = doc->createCDATASection(ch);
     7447        n.reset(doc->createCDATASection(ch));
    74547448    } else if (!entityName.isEmpty()) {
    7455         QDomEntityPrivate* e = new QDomEntityPrivate(doc, 0, entityName,
    7456                 QString(), QString(), QString());
     7449        QScopedPointer<QDomEntityPrivate> e(new QDomEntityPrivate(doc, 0, entityName,
     7450                QString(), QString(), QString()));
    74577451        e->value = ch;
    7458         doc->doctype()->appendChild(e);
    7459         n = doc->createEntityReference(entityName);
     7452        doc->doctype()->appendChild(e.data());
     7453        e.take();
     7454        n.reset(doc->createEntityReference(entityName));
    74607455    } else {
    7461         n = doc->createTextNode(ch);
     7456        n.reset(doc->createTextNode(ch));
    74627457    }
    74637458    n->setLocation(locator->lineNumber(), locator->columnNumber());
    7464     node->appendChild(n);
     7459    node->appendChild(n.data());
     7460    n.take();
    74657461
    74667462    return true;
Note: See TracChangeset for help on using the changeset viewer.