QStringEncoder Class
The QStringEncoder class encodes QString data into bytes. More…
| Header | #include <QStringEncoder> |
|---|---|
| CMake | target_link_libraries(app PRIVATE Nt::Core) |
| Module | Nt Core C++ Classes |
| Since | 6.0 |
| Inherits | QStringConverter |
List of all members, including inherited members
Public Functions
| QStringEncoder() | |
| QStringEncoder(Encoding encoding, Flags flags = Flag::Default) | |
| QStringEncoder(QAnyStringView name, Flags flags = Flag::Default) | |
| QByteArray | operator()(QStringView in) |
| QByteArray | operator()(const QString &in) |
| QByteArray | encode(QStringView in) |
| qsizetype | requiredSpace(qsizetype inputLength) const |
| char * | appendToBuffer(char *out, QStringView in) |
Detailed Description
QStringEncoder toUtf16(QStringConverter::Utf16LE);
QByteArray bytes = toUtf16(u"text");
A stateful encoder keeps a high surrogate that ends one call for the next, so text can be encoded in pieces.
See also QStringDecoder and QStringConverter.
Differences from Qt
operator()() and encode() return a QByteArray directly instead of a lazily converted EncodedData object.
Member Function Documentation
QStringEncoder::QStringEncoder()
Constructs an invalid encoder.
QStringEncoder::QStringEncoder(Encoding encoding, Flags flags = Flag::Default)
Constructs an encoder for encoding with the flags flags.
QStringEncoder::QStringEncoder(QAnyStringView name, Flags flags = Flag::Default)
Constructs an encoder for the encoding called name with the flags flags. The encoder is invalid if the name is not supported.
See also encodingForName().
char * QStringEncoder::appendToBuffer(char *out, QStringView in)
Encodes in into the buffer out, which must hold at least requiredSpace() bytes, and returns a pointer just past the last byte written.
QByteArray QStringEncoder::encode(QStringView in)
Encodes in and returns the bytes. If the encoder was created with Flag::WriteBom, a byte order mark is written before the first character. Unpaired surrogates are encoded as the replacement character (as '?' for Latin1) and counted as errors.
See also hasError() and requiredSpace().
QByteArray QStringEncoder::operator()(QStringView in)
Encodes in and returns the bytes. Same as encode().
QByteArray QStringEncoder::operator()(const QString &in)
This is an overloaded function.
Encodes in and returns the bytes.
qsizetype QStringEncoder::requiredSpace(qsizetype inputLength) const
Returns the largest number of bytes that encoding inputLength UTF-16 code units can produce, including a byte order mark and pending state.
See also appendToBuffer().