![]() |
Qt 6.x
The Qt SDK
|
\inmodule QtCore More...
#include <qstringconverter.h>
Classes | |
struct | DecodedData |
Public Member Functions | |
constexpr | QStringEncoder () noexcept |
Default constructs an encoder. | |
constexpr | QStringEncoder (Encoding encoding, Flags flags=Flag::Default) |
Creates an encoder object using encoding and flags. | |
QStringEncoder (const char *name, Flags flags=Flag::Default) | |
Creates an encoder object using name and flags. | |
Q_WEAK_OVERLOAD DecodedData< const QString & > | operator() (const QString &str) |
DecodedData< QStringView > | operator() (QStringView in) |
Converts in and returns the data as a byte array. | |
Q_WEAK_OVERLOAD DecodedData< const QString & > | encode (const QString &str) |
DecodedData< QStringView > | encode (QStringView in) |
qsizetype | requiredSpace (qsizetype inputLength) const |
Returns the maximum amount of characters required to be able to process inputLength decoded data. | |
char * | appendToBuffer (char *out, QStringView in) |
Encodes in and writes the encoded result into the buffer starting at out. | |
![]() | |
QStringConverter (QStringConverter &&)=default | |
QStringConverter & | operator= (QStringConverter &&)=default |
bool | isValid () const noexcept |
Returns true if this is a valid string converter that can be used for encoding or decoding text. | |
void | resetState () noexcept |
Resets the internal state of the converter, clearing potential errors or partial conversions. | |
bool | hasError () const noexcept |
Returns true if a conversion could not correctly convert a character. | |
Q_CORE_EXPORT const char * | name () const noexcept |
Returns the canonical name of the encoding this QStringConverter can encode or decode. | |
Protected Member Functions | |
constexpr | QStringEncoder (const Interface *i) noexcept |
![]() | |
constexpr | QStringConverter () noexcept |
constexpr | QStringConverter (Encoding encoding, Flags f) |
constexpr | QStringConverter (const Interface *i) noexcept |
Q_CORE_EXPORT | QStringConverter (const char *name, Flags f) |
~QStringConverter ()=default | |
![]() | |
~QStringConverterBase ()=default | |
Additional Inherited Members | |
![]() | |
enum | Encoding { Utf8 , Utf16 , Utf16LE , Utf16BE , Utf32 , Utf32LE , Utf32BE , Latin1 , System , LastEncoding = System } |
\value Utf8 Create a converter to or from UTF-8 \value Utf16 Create a converter to or from UTF-16. More... | |
![]() | |
enum class | Flag { Default = 0 , Stateless = 0x1 , ConvertInvalidToNull = 0x2 , WriteBom = 0x4 , ConvertInitialBom = 0x8 , UsesIcu = 0x10 } |
![]() | |
static Q_CORE_EXPORT std::optional< Encoding > | encodingForName (const char *name) noexcept |
Convert name to the corresponding \l Encoding member, if there is one. | |
static Q_CORE_EXPORT const char * | nameForEncoding (Encoding e) |
Returns the canonical name for encoding e. | |
static Q_CORE_EXPORT std::optional< Encoding > | encodingForData (QByteArrayView data, char16_t expectedFirstCharacter=0) noexcept |
Returns the encoding for the content of data if it can be determined. | |
static Q_CORE_EXPORT std::optional< Encoding > | encodingForHtml (QByteArrayView data) |
Tries to determine the encoding of the HTML in data by looking at leading byte order marks or a charset specifier in the HTML meta tag. | |
![]() | |
const Interface * | iface |
State | state |
\inmodule QtCore
The QStringEncoder class provides a state-based encoder for text. \reentrant
A text encoder converts text from Qt's internal representation into an encoded text format using a specific encoding.
Converting a string from Unicode to the local encoding can be achieved using the following code:
The encoder remembers any state that is required between calls, so converting data received in chunks, for example, when receiving it over a network, is just as easy, by calling the encoder whenever new data is available:
The QStringEncoder object maintains state between chunks and therefore works correctly even if a UTF-16 surrogate character is split between chunks.
QStringEncoder objects can't be copied because of their internal state, but can be moved.
Definition at line 22 of file qstringconverter.h.
|
inlineexplicitconstexprprotectednoexcept |
Definition at line 25 of file qstringconverter.h.
|
inlineconstexprnoexcept |
Default constructs an encoder.
The default encoder is not valid, and can't be used for converting text.
Definition at line 29 of file qstringconverter.h.
|
inlineexplicitconstexpr |
Creates an encoder object using encoding and flags.
Definition at line 32 of file qstringconverter.h.
|
inlineexplicit |
Creates an encoder object using name and flags.
If name is not the name of a known encoding an invalid converter will get created.
Definition at line 35 of file qstringconverter.h.
|
inline |
Encodes in and writes the encoded result into the buffer starting at out.
Returns a pointer to the end of the data written.
Definition at line 66 of file qstringconverter.h.
References QStringConverter::Interface::fromUtf16, QStringConverter::iface, QStringConverterBase::State::invalidChars, out, and QStringConverter::state.
Referenced by toSQLTCHAR().
|
inline |
Definition at line 58 of file qstringconverter.h.
References str.
Referenced by QQuickDragAttachedPrivate::createMimeData().
|
inline |
Definition at line 60 of file qstringconverter.h.
|
inline |
Definition at line 53 of file qstringconverter.h.
References str.
|
inline |
Converts in and returns the data as a byte array.
Definition at line 55 of file qstringconverter.h.
Returns the maximum amount of characters required to be able to process inputLength decoded data.
Definition at line 64 of file qstringconverter.h.
References QStringConverter::Interface::fromUtf16Len, and QStringConverter::iface.
Referenced by toSQLTCHAR().