summaryrefslogtreecommitdiff
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.cpp90
1 files changed, 48 insertions, 42 deletions
diff --git a/src/xml/sax/qxml.cpp b/src/xml/sax/qxml.cpp
index 3b1726b7d8..96a509d02d 100644
--- a/src/xml/sax/qxml.cpp
+++ b/src/xml/sax/qxml.cpp
@@ -272,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
@@ -312,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++); }
@@ -358,7 +361,7 @@ private:
bool contentCharDataRead;
// helper classes
- QXmlLocator *locator;
+ QScopedPointer<QXmlLocator> locator;
QXmlNamespaceSupport namespaceSupport;
// error string
@@ -553,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;
@@ -565,9 +568,10 @@ QXmlParseException::QXmlParseException(const QString& name, int c, int l,
/*!
Creates a copy of \a other.
*/
-QXmlParseException::QXmlParseException(const QXmlParseException& other)
+QXmlParseException::QXmlParseException(const QXmlParseException& other) :
+ d(new QXmlParseExceptionPrivate(*other.d))
{
- d = new QXmlParseExceptionPrivate(*other.d);
+
}
/*!
@@ -575,7 +579,6 @@ QXmlParseException::QXmlParseException(const QXmlParseException& other)
*/
QXmlParseException::~QXmlParseException()
{
- delete d;
}
/*!
@@ -944,8 +947,9 @@ void QXmlNamespaceSupport::popContext()
*/
void QXmlNamespaceSupport::reset()
{
+ QXmlNamespaceSupportPrivate *newD = new QXmlNamespaceSupportPrivate;
delete d;
- d = new QXmlNamespaceSupportPrivate;
+ d = newD;
}
@@ -1276,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;
+ }
}
/*!
@@ -2731,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()
@@ -2743,8 +2767,10 @@ QXmlSimpleReaderPrivate::~QXmlSimpleReaderPrivate()
void QXmlSimpleReaderPrivate::initIncrementalParsing()
{
- delete parseStack;
- parseStack = new QStack<ParseState>;
+ if( parseStack )
+ parseStack->clear();
+ else
+ parseStack = new QStack<ParseState>;
}
/*********************************************
@@ -3111,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;
}
/*!
@@ -3137,9 +3146,6 @@ QXmlSimpleReader::QXmlSimpleReader()
*/
QXmlSimpleReader::~QXmlSimpleReader()
{
- Q_D(QXmlSimpleReader);
- delete d->locator;
- delete d;
}
/*!
@@ -3422,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();