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/corelib/serialization/qtextstream.cpp | |
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/corelib/serialization/qtextstream.cpp')
-rw-r--r-- | src/corelib/serialization/qtextstream.cpp | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/corelib/serialization/qtextstream.cpp b/src/corelib/serialization/qtextstream.cpp index a2af401a41..df683d74da 100644 --- a/src/corelib/serialization/qtextstream.cpp +++ b/src/corelib/serialization/qtextstream.cpp @@ -3157,6 +3157,45 @@ QTextStream &bom(QTextStream &stream) } // namespace Qt + +/*! + Sets the encoding for this stream to \a encoding. The encoding is used for + decoding any data that is read from the assigned device, and for + encoding any data that is written. By default, + QStringConverter::Utf8 is used, and automatic unicode + detection is enabled. + + If QTextStream operates on a string, this function does nothing. + + \warning If you call this function while the text stream is reading + from an open sequential socket, the internal buffer may still contain + text decoded using the old encoding. + + \sa encoding(), setAutoDetectUnicode(), setLocale() +*/ +void QTextStream::setEncoding(QStringConverter::Encoding encoding) +{ + Q_D(QTextStream); + d->encoding = encoding; +#if QT_CONFIG(textcodec) + // FIXME: This is temporary until QTextStream is converted to use QStringConverter + const char *name = QStringConverter::nameForEncoding(encoding); + auto codec = QTextCodec::codecForName(name); + setCodec(codec); +#endif +} + +/*! + Returns the encoding that is current assigned to the stream. + + \sa setEncoding(), setAutoDetectUnicode(), locale() +*/ +QStringConverter::Encoding QTextStream::encoding() const +{ + Q_D(const QTextStream); + return d->encoding; +} + /*! Sets the codec for this stream to \a codec. The codec is used for decoding any data that is read from the assigned device, and for |