diff options
author | Lars Knoll <lars.knoll@qt.io> | 2020-04-28 17:01:11 +0200 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2020-05-14 07:50:13 +0200 |
commit | 33bb695a2895fb7199b256a4fd76923c32a8587a (patch) | |
tree | 78bcb9e1611433be28bd788040db7972017976b8 /src/xml | |
parent | 8835c64f795b641619b852c2055605afd9d16442 (diff) |
Start porting QTextStream away from QTextCodec
As a first step add setEncoding/encoding() methods that use the
QStringConverter::Encoding enum, and port all uses of setCodec()/
codec() over to the new API.
Internally QTextStream still uses QTextCodec, this will be ported
over to QStringConverter in a follow-up change.
Change-Id: Icd764cf47b449b57f4ebd010c2dad89e6717d6c0
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/xml')
-rw-r--r-- | src/xml/dom/qdom.cpp | 21 |
1 files changed, 9 insertions, 12 deletions
diff --git a/src/xml/dom/qdom.cpp b/src/xml/dom/qdom.cpp index 022de70090..5224c8b31c 100644 --- a/src/xml/dom/qdom.cpp +++ b/src/xml/dom/qdom.cpp @@ -5964,8 +5964,6 @@ void QDomDocumentPrivate::saveDocument(QTextStream& s, const int indent, QDomNod #if QT_CONFIG(textcodec) && QT_CONFIG(regularexpression) const QDomNodePrivate* n = first; - QTextCodec *codec = nullptr; - if (n && n->isProcessingInstruction() && n->nodeName() == QLatin1String("xml")) { // we have an XML declaration QString data = n->nodeValue(); @@ -5974,13 +5972,14 @@ void QDomDocumentPrivate::saveDocument(QTextStream& s, const int indent, QDomNod QString enc = match.captured(3); if (enc.isEmpty()) enc = match.captured(5); - if (!enc.isEmpty()) - codec = QTextCodec::codecForName(std::move(enc).toLatin1()); + if (!enc.isEmpty()) { + auto encoding = QStringConverter::encodingForName(enc.toUtf8().constData()); + if (!encoding) + qWarning() << "QDomDocument::save(): Unsupported encoding" << enc << "specified."; + else + s.setEncoding(encoding.value()); + } } - if (!codec) - codec = QTextCodec::codecForName("UTF-8"); - if (codec) - s.setCodec(codec); #endif bool doc = false; @@ -5998,11 +5997,9 @@ void QDomDocumentPrivate::saveDocument(QTextStream& s, const int indent, QDomNod // Write out the XML declaration. #if !QT_CONFIG(textcodec) - const QLatin1String codecName("iso-8859-1"); + const QLatin1String codecName("UTF-8"); #else - const QTextCodec *const codec = s.codec(); - Q_ASSERT_X(codec, "QDomNode::save()", "A codec must be specified in the text stream."); - const QByteArray codecName = codec->name(); + const QByteArray codecName = QStringConverter::nameForEncoding(s.encoding()); #endif s << "<?xml version=\"1.0\" encoding=\"" |