From be04ee67deb2955f0e1f5915fb17c5411377f7d4 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Tue, 28 Apr 2020 11:47:21 +0200 Subject: [PATCH] Correctly flag remaining chars for the ICU codec This will help us get rid of an extremely ugly hack in QTextStream, where we copy the state. Change-Id: If3e15eeb4e35c8607be54dd11c09ddfed87a4d93 Reviewed-by: Thiago Macieira --- src/corelib/codecs/qicucodec.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/corelib/codecs/qicucodec.cpp b/src/corelib/codecs/qicucodec.cpp index f9092277b23..8a6dfc756fa 100644 --- a/src/corelib/codecs/qicucodec.cpp +++ b/src/corelib/codecs/qicucodec.cpp @@ -614,6 +614,9 @@ QString QIcuCodec::convertToUnicode(const char *chars, int length, QTextCodec::C qDebug("convertToUnicode failed: %s", u_errorName(error)); break; } + // flag the state if we have incomplete input + if (error == U_TRUNCATED_CHAR_FOUND) + state->remainingChars = 1; convertedChars = uc - (UChar *)string.data(); if (chars >= end) @@ -649,6 +652,10 @@ QByteArray QIcuCodec::convertFromUnicode(const QChar *unicode, int length, QText nullptr, false, &error); if (!U_SUCCESS(error)) qDebug("convertFromUnicode failed: %s", u_errorName(error)); + // flag the state if we have incomplete input + if (error == U_TRUNCATED_CHAR_FOUND) + state->remainingChars = 1; + convertedChars = ch - string.data(); if (uc >= end) break;