Qt 4.8
Public Functions | Properties | List of all members
QTextEncoder Class Reference

The QTextEncoder class provides a state-based encoder. More...

#include <qtextcodec.h>

Public Functions

QByteArray fromUnicode (const QString &str)
 Converts the Unicode string str into an encoded QByteArray. More...
 
QByteArray fromUnicode (const QChar *uc, int len)
 Converts len characters (not bytes) from uc, and returns the result in a QByteArray. More...
 
bool hasFailure () const
 Determines whether the eecoder encountered a failure while decoding the input. More...
 
 QTextEncoder (const QTextCodec *codec)
 Constructs a text encoder for the given codec. More...
 
 QTextEncoder (const QTextCodec *codec, QTextCodec::ConversionFlags flags)
 Constructs a text encoder for the given codec and conversion flags. More...
 
 ~QTextEncoder ()
 Destroys the encoder. More...
 

Properties

const QTextCodecc
 
QTextCodec::ConverterState state
 

Detailed Description

The QTextEncoder class provides a state-based encoder.

Note
This class or function is reentrant.

A text encoder converts text from Unicode into an encoded text format using a specific codec.

The encoder converts Unicode into another format, remembering any state that is required between calls.

See also
QTextCodec::makeEncoder(), QTextDecoder

Definition at line 160 of file qtextcodec.h.

Constructors and Destructors

◆ QTextEncoder() [1/2]

QTextEncoder::QTextEncoder ( const QTextCodec codec)
inlineexplicit

Constructs a text encoder for the given codec.

Definition at line 163 of file qtextcodec.h.

163 : c(codec), state() {}
const QTextCodec * c
Definition: qtextcodec.h:173
QTextCodec::ConverterState state
Definition: qtextcodec.h:174

◆ QTextEncoder() [2/2]

QTextEncoder::QTextEncoder ( const QTextCodec codec,
QTextCodec::ConversionFlags  flags 
)

Constructs a text encoder for the given codec and conversion flags.

Since
4.7

Definition at line 1521 of file qtextcodec.cpp.

1522  : c(codec), state()
1523 {
1524  state.flags = flags;
1525 }
const QTextCodec * c
Definition: qtextcodec.h:173
ConversionFlags flags
Definition: qtextcodec.h:106
QTextCodec::ConverterState state
Definition: qtextcodec.h:174

◆ ~QTextEncoder()

QTextEncoder::~QTextEncoder ( )

Destroys the encoder.

Definition at line 1530 of file qtextcodec.cpp.

1531 {
1532 }

Functions

◆ fromUnicode() [1/2]

QByteArray QTextEncoder::fromUnicode ( const QString str)

Converts the Unicode string str into an encoded QByteArray.

Definition at line 1551 of file qtextcodec.cpp.

Referenced by QXmlStreamWriterPrivate::checkIfASCIICompatibleCodec(), fromUnicode(), and QXmlStreamWriterPrivate::write().

1552 {
1553  QByteArray result = c->fromUnicode(str.constData(), str.length(), &state);
1554  return result;
1555 }
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
QByteArray fromUnicode(const QString &uc) const
Converts str from Unicode to the encoding of this codec, and returns the result in a QByteArray...
const QTextCodec * c
Definition: qtextcodec.h:173
QTextCodec::ConverterState state
Definition: qtextcodec.h:174
const QChar * constData() const
Returns a pointer to the data stored in the QString.
Definition: qstring.h:712

◆ fromUnicode() [2/2]

QByteArray QTextEncoder::fromUnicode ( const QChar uc,
int  len 
)

Converts len characters (not bytes) from uc, and returns the result in a QByteArray.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 1566 of file qtextcodec.cpp.

1567 {
1568  QByteArray result = c->fromUnicode(uc, len, &state);
1569  return result;
1570 }
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
QByteArray fromUnicode(const QString &uc) const
Converts str from Unicode to the encoding of this codec, and returns the result in a QByteArray...
const QTextCodec * c
Definition: qtextcodec.h:173
QTextCodec::ConverterState state
Definition: qtextcodec.h:174

◆ hasFailure()

bool QTextEncoder::hasFailure ( ) const

Determines whether the eecoder encountered a failure while decoding the input.

Warning
This function is not part of the public interface.
Since
4.5 If an error was encountered, the produced result is undefined, and gets converted as according to the conversion flags.

Definition at line 1543 of file qtextcodec.cpp.

1544 {
1545  return state.invalidChars != 0;
1546 }
QTextCodec::ConverterState state
Definition: qtextcodec.h:174

Properties

◆ c

const QTextCodec* QTextEncoder::c
private

Definition at line 173 of file qtextcodec.h.

Referenced by fromUnicode().

◆ state

QTextCodec::ConverterState QTextEncoder::state
private

Definition at line 174 of file qtextcodec.h.

Referenced by fromUnicode(), hasFailure(), and QTextEncoder().


The documentation for this class was generated from the following files: