summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDenis Dzyubenko <denis.dzyubenko@nokia.com>2009-06-10 20:15:00 (GMT)
committerDenis Dzyubenko <denis.dzyubenko@nokia.com>2009-06-11 19:04:14 (GMT)
commit52392292c8fa096e3b0bb692dedce66924ab3305 (patch)
tree5eb54ee501896ffd37473e490580e0072644da87
parenta2baabcfcb60a7a0e5d3926ad6938983e50dfefc (diff)
downloadQt-52392292c8fa096e3b0bb692dedce66924ab3305.zip
Qt-52392292c8fa096e3b0bb692dedce66924ab3305.tar.gz
Qt-52392292c8fa096e3b0bb692dedce66924ab3305.tar.bz2
Skip the byte order mark when converting the utf16 and utf32 data
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
-rw-r--r--src/corelib/codecs/qutfcodec.cpp4
-rw-r--r--tests/auto/qtextstream/tst_qtextstream.cpp14
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