From 767319a5aac2462df84431917b3724f884091036 Mon Sep 17 00:00:00 2001 From: Luca Bellonda Date: Wed, 1 Jun 2016 00:06:13 +0200 Subject: Add support for 8bit encodings not ASCII compatible in QXMLStreamWriter. When using a 8 bit encoding to write a file, a test discovers if the encoding is really ASCII compatible by examining a letter and one of the XML reserved characters. EBCDIC, in the current base, was not well handled. [ChangeLog][QtCore][QXmlStreamWriter] Fixed a bug that prevented the generation of valid XML files when using encoding with 8 bit per character but not ASCII compatible. QXMLStreamWriter generated XML markup using always ASCII in this case. Change-Id: I9c86a122dd91b2290d50c358638442f99777d4ae Reviewed-by: Thiago Macieira --- src/corelib/xml/qxmlstream.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/corelib/xml/qxmlstream.cpp b/src/corelib/xml/qxmlstream.cpp index 64a130e45a..a235145669 100644 --- a/src/corelib/xml/qxmlstream.cpp +++ b/src/corelib/xml/qxmlstream.cpp @@ -3019,10 +3019,14 @@ void QXmlStreamWriterPrivate::checkIfASCIICompatibleCodec() { #ifndef QT_NO_TEXTCODEC Q_ASSERT(encoder); - // assumes ASCII-compatibility for all 8-bit encodings - QChar space = QLatin1Char(' '); - const QByteArray bytes = encoder->fromUnicode(&space, 1); - isCodecASCIICompatible = (bytes.count() == 1); + // test ASCII-compatibility using the letter 'a' + QChar letterA = QLatin1Char('a'); + const QByteArray bytesA = encoder->fromUnicode(&letterA, 1); + const bool isCodecASCIICompatibleA = (bytesA.count() == 1) && (bytesA[0] == 0x61) ; + QChar letterLess = QLatin1Char('<'); + const QByteArray bytesLess = encoder->fromUnicode(&letterLess, 1); + const bool isCodecASCIICompatibleLess = (bytesLess.count() == 1) && (bytesLess[0] == 0x3C) ; + isCodecASCIICompatible = isCodecASCIICompatibleA && isCodecASCIICompatibleLess ; #else isCodecASCIICompatible = true; #endif -- cgit v1.2.3