From 52392292c8fa096e3b0bb692dedce66924ab3305 Mon Sep 17 00:00:00 2001 From: Denis Dzyubenko Date: Wed, 10 Jun 2009 22:15:00 +0200 Subject: Skip the byte order mark when converting the utf16 and utf32 data MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When reading one character at a time (as QTextStream::pos does) the byte order mark could be ignored. This happens only with UTF-16 BE/LE and UTF-32 BE/LE codecs. This fixes the qtextstream autotest. Author: Olivier Goffart Author: João Abecasis --- src/corelib/codecs/qutfcodec.cpp | 4 ++-- tests/auto/qtextstream/tst_qtextstream.cpp | 14 +++++++++++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/corelib/codecs/qutfcodec.cpp b/src/corelib/codecs/qutfcodec.cpp index d9defe1..6611315 100644 --- a/src/corelib/codecs/qutfcodec.cpp +++ b/src/corelib/codecs/qutfcodec.cpp @@ -387,7 +387,7 @@ QString QUtf16Codec::convertToUnicode(const char *chars, int len, ConverterState result.truncate(qch - result.unicode()); if (state) { - if (endian != Detect) + if (headerdone) state->flags |= IgnoreHeader; state->state_data[Endian] = endian; if (half) { @@ -569,7 +569,7 @@ QString QUtf32Codec::convertToUnicode(const char *chars, int len, ConverterState result.truncate(qch - result.unicode()); if (state) { - if (endian != Detect) + if (headerdone) state->flags |= IgnoreHeader; state->state_data[Endian] = endian; state->remainingChars = num; diff --git a/tests/auto/qtextstream/tst_qtextstream.cpp b/tests/auto/qtextstream/tst_qtextstream.cpp index 358b4b6..cf495d5 100644 --- a/tests/auto/qtextstream/tst_qtextstream.cpp +++ b/tests/auto/qtextstream/tst_qtextstream.cpp @@ -552,8 +552,8 @@ void tst_QTextStream::generateLineData(bool for_QString) QTest::newRow("threelines/crlf/crlf/crlf") << QByteArray("ole\r\ndole\r\ndoffen\r\n") << (QStringList() << "ole" << "dole" << "doffen"); QTest::newRow("threelines/crlf/crlf/nothing") << QByteArray("ole\r\ndole\r\ndoffen") << (QStringList() << "ole" << "dole" << "doffen"); - // utf-16 if (!for_QString) { + // utf-16 // one line QTest::newRow("utf16-BE/nothing") << QByteArray("\xfe\xff" @@ -593,6 +593,18 @@ void tst_QTextStream::generateLineData(bool for_QString) "\xe5\x00\x67\x00\x65\x00\x0a\x00" "\xe5\x00\x67\x00\x65\x00\x0a\x00", 26) << (QStringList() << "\345ge" << "\345ge" << "\345ge"); + + // utf-32 + QTest::newRow("utf32-BE/twolines") + << QByteArray("\x00\x00\xfe\xff" + "\x00\x00\x00\xe5\x00\x00\x00\x67\x00\x00\x00\x65\x00\x00\x00\x0a" + "\x00\x00\x00\xe5\x00\x00\x00\x67\x00\x00\x00\x65\x00\x00\x00\x0a", 36) + << (QStringList() << "\345ge" << "\345ge"); + QTest::newRow("utf32-LE/twolines") + << QByteArray("\xff\xfe\x00\x00" + "\xe5\x00\x00\x00\x67\x00\x00\x00\x65\x00\x00\x00\x0a\x00\x00\x00" + "\xe5\x00\x00\x00\x67\x00\x00\x00\x65\x00\x00\x00\x0a\x00\x00\x00", 36) + << (QStringList() << "\345ge" << "\345ge"); } // partials -- cgit v0.12