6.0.0-rc4Source

QStringDecoder Class

The QStringDecoder class decodes bytes into a QString. More…

Header#include <QStringDecoder>
CMaketarget_link_libraries(app PRIVATE Nt::Core)
ModuleNt Core C++ Classes
Since6.0
InheritsQStringConverter

List of all members, including inherited members

Public Functions

QStringDecoder()
QStringDecoder(Encoding encoding, Flags flags = Flag::Default)
QStringDecoder(QAnyStringView name, Flags flags = Flag::Default)
QStringoperator()(QByteArrayView ba)
QStringoperator()(const QByteArray &ba)
QStringdecode(QByteArrayView ba)
qsizetyperequiredSpace(qsizetype inputLength) const
QChar *appendToBuffer(QChar *out, QByteArrayView ba)
char16_t *appendToBuffer(char16_t *out, QByteArrayView ba)

Static Public Members

QStringDecoderdecoderForHtml(QByteArrayView data)

Detailed Description

QStringDecoder fromUtf8(QStringConverter::Utf8);
QString text = fromUtf8(chunk1);
text += fromUtf8(chunk2); // a sequence split between chunks is joined

See also QStringEncoder and QStringConverter.

Differences from Qt

operator()() and decode() return a QString directly instead of a lazily converted DecodedData object.

Member Function Documentation

QStringDecoder::QStringDecoder()

Constructs an invalid decoder.

[explicit] QStringDecoder::QStringDecoder(Encoding encoding, Flags flags = Flag::Default)

Constructs a decoder for encoding with the flags flags.

[explicit] QStringDecoder::QStringDecoder(QAnyStringView name, Flags flags = Flag::Default)

Constructs a decoder for the encoding called name with the flags flags. The decoder is invalid if the name is not supported.

See also encodingForName().

QChar * QStringDecoder::appendToBuffer(QChar *out, QByteArrayView ba)

Decodes ba into the buffer out, which must hold at least requiredSpace() characters, and returns a pointer just past the last character written.

char16_t * QStringDecoder::appendToBuffer(char16_t *out, QByteArrayView ba)

This is an overloaded function.

Decodes ba into the buffer out and returns a pointer just past the last character written.

QString QStringDecoder::decode(QByteArrayView ba)

Decodes ba and returns the text. Unless the decoder is Flag::Stateless, an incomplete sequence at the end of ba is kept and completed by the next call. Invalid sequences become the replacement character U+FFFD (U+0000 with Flag::ConvertInvalidToNull) and are counted as errors. A byte order mark at the start of the data is skipped unless Flag::ConvertInitialBom is set; for Utf16 and Utf32 it also selects the byte order.

See also hasError() and resetState().

[static] QStringDecoder QStringDecoder::decoderForHtml(QByteArrayView data)

Returns a decoder for the HTML document data, using the encoding found by encodingForHtml(). The decoder is invalid if the document names an encoding that is not supported.

QString QStringDecoder::operator()(QByteArrayView ba)

Decodes ba and returns the text. Same as decode().

QString QStringDecoder::operator()(const QByteArray &ba)

This is an overloaded function.

Decodes ba and returns the text.

qsizetype QStringDecoder::requiredSpace(qsizetype inputLength) const

Returns the largest number of UTF-16 code units that decoding inputLength bytes can produce, including pending state.

See also appendToBuffer().