From 40909863e9eb17e0d0469ade608426dbbd08b43e Mon Sep 17 00:00:00 2001 From: Peter Hartmann Date: Tue, 29 Sep 2009 11:29:01 +0200 Subject: QDom: set the codec to UTF-8 if codec not present or unknown we were trying to get a codec even for unknown names. Now, we always set the codec to UTF8 if the field is not present or we do not know the codec. Reviewed-by: Paul --- src/xml/dom/qdom.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/xml/dom/qdom.cpp b/src/xml/dom/qdom.cpp index 3ae91d3..b06fbeb 100644 --- a/src/xml/dom/qdom.cpp +++ b/src/xml/dom/qdom.cpp @@ -6438,22 +6438,23 @@ void QDomDocumentPrivate::saveDocument(QTextStream& s, const int indent, QDomNod #ifndef QT_NO_TEXTCODEC const QDomNodePrivate* n = first; + QTextCodec *codec = 0; + if (n && n->isProcessingInstruction() && n->nodeName() == QLatin1String("xml")) { // we have an XML declaration QString data = n->nodeValue(); QRegExp encoding(QString::fromLatin1("encoding\\s*=\\s*((\"([^\"]*)\")|('([^']*)'))")); encoding.indexIn(data); QString enc = encoding.cap(3); - if (enc.isEmpty()) { - enc = encoding.cap(5); - } if (enc.isEmpty()) - s.setCodec(QTextCodec::codecForName("UTF-8")); - else - s.setCodec(QTextCodec::codecForName(enc.toLatin1().data())); - } else { - s.setCodec(QTextCodec::codecForName("UTF-8")); + enc = encoding.cap(5); + if (!enc.isEmpty()) + codec = QTextCodec::codecForName(enc.toLatin1().data()); } + if (!codec) + codec = QTextCodec::codecForName("UTF-8"); + if (codec) + s.setCodec(codec); #endif bool doc = false; -- cgit v0.12