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

The QTextDecoder class provides a state-based decoder. More...

#include <qtextcodec.h>

Public Functions

bool hasFailure () const
 Determines whether the decoder encountered a failure while decoding the input. More...
 
 QTextDecoder (const QTextCodec *codec)
 Constructs a text decoder for the given codec. More...
 
 QTextDecoder (const QTextCodec *codec, QTextCodec::ConversionFlags flags)
 Constructs a text decoder for the given codec and conversion flags. More...
 
QString toUnicode (const char *chars, int len)
 Converts the first len bytes in chars to Unicode, returning the result. More...
 
QString toUnicode (const QByteArray &ba)
 Converts the bytes in the byte array specified by ba to Unicode and returns the result. More...
 
void toUnicode (QString *target, const char *chars, int len)
 The converted string is returned in target. More...
 
 ~QTextDecoder ()
 Destroys the decoder. More...
 

Properties

const QTextCodecc
 
QTextCodec::ConverterState state
 

Detailed Description

The QTextDecoder class provides a state-based decoder.

Note
This class or function is reentrant.

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

The decoder converts text in this format into Unicode, remembering any state that is required between calls.

See also
QTextCodec::makeDecoder(), QTextEncoder

Definition at line 177 of file qtextcodec.h.

Constructors and Destructors

◆ QTextDecoder() [1/2]

QTextDecoder::QTextDecoder ( const QTextCodec codec)
inlineexplicit

Constructs a text decoder for the given codec.

Definition at line 180 of file qtextcodec.h.

180 : c(codec), state() {}
QTextCodec::ConverterState state
Definition: qtextcodec.h:189
const QTextCodec * c
Definition: qtextcodec.h:188

◆ QTextDecoder() [2/2]

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

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

Since
4.7

Definition at line 1621 of file qtextcodec.cpp.

1622  : c(codec), state()
1623 {
1624  state.flags = flags;
1625 }
QTextCodec::ConverterState state
Definition: qtextcodec.h:189
ConversionFlags flags
Definition: qtextcodec.h:106
const QTextCodec * c
Definition: qtextcodec.h:188

◆ ~QTextDecoder()

QTextDecoder::~QTextDecoder ( )

Destroys the decoder.

Definition at line 1630 of file qtextcodec.cpp.

1631 {
1632 }

Functions

◆ hasFailure()

bool QTextDecoder::hasFailure ( ) const

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

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

Definition at line 1888 of file qtextcodec.cpp.

Referenced by QXmlStreamReaderPrivate::getChar_helper(), and QXmlStreamReaderPrivate::parse().

1889 {
1890  return state.invalidChars != 0;
1891 }
QTextCodec::ConverterState state
Definition: qtextcodec.h:189

◆ toUnicode() [1/3]

QString QTextDecoder::toUnicode ( const char *  chars,
int  len 
)

Converts the first len bytes in chars to Unicode, returning the result.

If not all characters are used (e.g. if only part of a multi-byte encoding is at the end of the characters), the decoder remembers enough state to continue with the next call to this function.

Definition at line 1644 of file qtextcodec.cpp.

Referenced by QXmlStreamReaderPrivate::getChar_helper(), and QXmlStreamReaderPrivate::startDocument().

1645 {
1646  return c->toUnicode(chars, len, &state);
1647 }
QTextCodec::ConverterState state
Definition: qtextcodec.h:189
QString toUnicode(const QByteArray &) const
Converts a from the encoding of this codec to Unicode, and returns the result in a QString...
const QTextCodec * c
Definition: qtextcodec.h:188

◆ toUnicode() [2/3]

QString QTextDecoder::toUnicode ( const QByteArray ba)

Converts the bytes in the byte array specified by ba to Unicode and returns the result.

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 1685 of file qtextcodec.cpp.

1686 {
1687  return c->toUnicode(ba.constData(), ba.length(), &state);
1688 }
QTextCodec::ConverterState state
Definition: qtextcodec.h:189
int length() const
Same as size().
Definition: qbytearray.h:356
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
QString toUnicode(const QByteArray &) const
Converts a from the encoding of this codec to Unicode, and returns the result in a QString...
const QTextCodec * c
Definition: qtextcodec.h:188

◆ toUnicode() [3/3]

void QTextDecoder::toUnicode ( QString target,
const char *  chars,
int  len 
)

The converted string is returned in target.

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 1657 of file qtextcodec.cpp.

1658 {
1659  Q_ASSERT(target);
1660  switch (c->mibEnum()) {
1661  case 106: // utf8
1662  static_cast<const QUtf8Codec*>(c)->convertToUnicode(target, chars, len, &state);
1663  break;
1664  case 4: { // latin1
1665  target->resize(len);
1666  ushort *data = (ushort*)target->data();
1667  for (int i = len; i >=0; --i)
1668  data[i] = (uchar) chars[i];
1669  } break;
1670  default:
1671  *target = c->toUnicode(chars, len, &state);
1672  }
1673 }
QTextCodec::ConverterState state
Definition: qtextcodec.h:189
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
QChar * data()
Returns a pointer to the data stored in the QString.
Definition: qstring.h:710
unsigned char uchar
Definition: qglobal.h:994
virtual int mibEnum() const =0
Subclasses of QTextCodec must reimplement this function.
static const char * data(const QByteArray &arr)
void resize(int size)
Sets the size of the string to size characters.
Definition: qstring.cpp:1353
QString toUnicode(const QByteArray &) const
Converts a from the encoding of this codec to Unicode, and returns the result in a QString...
unsigned short ushort
Definition: qglobal.h:995
const QTextCodec * c
Definition: qtextcodec.h:188

Properties

◆ c

const QTextCodec* QTextDecoder::c
private

Definition at line 188 of file qtextcodec.h.

Referenced by QTextCodec::codecForHtml(), and toUnicode().

◆ state

QTextCodec::ConverterState QTextDecoder::state
private

Definition at line 189 of file qtextcodec.h.

Referenced by hasFailure(), QTextDecoder(), and toUnicode().


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