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

#include <qsimplecodec_p.h>

Inheritance diagram for QSimpleTextCodec:
QTextCodec

Public Types

enum  { numSimpleCodecs = 30 }
 
- Public Types inherited from QTextCodec
enum  ConversionFlag { DefaultConversion, ConvertInvalidToNull = 0x80000000, IgnoreHeader = 0x1, FreeFunction = 0x2 }
 

Public Functions

QList< QByteArrayaliases () const
 Subclasses can return a number of aliases for the codec in question. More...
 
QByteArray convertFromUnicode (const QChar *, int, ConverterState *) const
 QTextCodec subclasses must reimplement this function. More...
 
QString convertToUnicode (const char *, int, ConverterState *) const
 QTextCodec subclasses must reimplement this function. More...
 
int mibEnum () const
 Subclasses of QTextCodec must reimplement this function. More...
 
QByteArray name () const
 QTextCodec subclasses must reimplement this function. More...
 
 QSimpleTextCodec (int)
 
 ~QSimpleTextCodec ()
 
- Public Functions inherited from QTextCodec
bool canEncode (QChar) const
 Returns true if the Unicode character ch can be fully encoded with this codec; otherwise returns false. More...
 
bool canEncode (const QString &) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.s contains the string being tested for encode-ability. More...
 
QByteArray fromUnicode (const QString &uc) const
 Converts str from Unicode to the encoding of this codec, and returns the result in a QByteArray. More...
 
QByteArray fromUnicode (const QChar *in, int length, ConverterState *state=0) const
 Converts the first number of characters from the input array from Unicode to the encoding of this codec, and returns the result in a QByteArray. More...
 
QTextDecodermakeDecoder () const
 Creates a QTextDecoder which stores enough state to decode chunks of char * data to create chunks of Unicode data. More...
 
QTextDecodermakeDecoder (ConversionFlags flags) const
 
QTextEncodermakeEncoder () const
 Creates a QTextEncoder which stores enough state to encode chunks of Unicode data as char * data. More...
 
QTextEncodermakeEncoder (ConversionFlags flags) const
 
QString toUnicode (const QByteArray &) const
 Converts a from the encoding of this codec to Unicode, and returns the result in a QString. More...
 
QString toUnicode (const char *chars) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.chars contains the source characters. More...
 
QString toUnicode (const char *in, int length, ConverterState *state=0) const
 Converts the first size characters from the input from the encoding of this codec to Unicode, and returns the result in a QString. More...
 

Properties

int forwardIndex
 
QAtomicPointer< QByteArrayreverseMap
 

Additional Inherited Members

- Static Public Functions inherited from QTextCodec
static QList< QByteArrayavailableCodecs ()
 Returns the list of all available codecs, by name. More...
 
static QList< int > availableMibs ()
 Returns the list of MIBs for all available codecs. More...
 
static QTextCodeccodecForCStrings ()
 Returns the codec used by QString to convert to and from const char * and QByteArrays. More...
 
static QTextCodeccodecForHtml (const QByteArray &ba)
 Tries to detect the encoding of the provided snippet of HTML in the given byte array, ba, by checking the BOM (Byte Order Mark) and the content-type meta header and returns a QTextCodec instance that is capable of decoding the html to unicode. More...
 
static QTextCodeccodecForHtml (const QByteArray &ba, QTextCodec *defaultCodec)
 Tries to detect the encoding of the provided snippet of HTML in the given byte array, ba, by checking the BOM (Byte Order Mark) and the content-type meta header and returns a QTextCodec instance that is capable of decoding the html to unicode. More...
 
static QTextCodeccodecForLocale ()
 Returns a pointer to the codec most suitable for this locale. More...
 
static QTextCodeccodecForMib (int mib)
 Returns the QTextCodec which matches the MIBenum mib. More...
 
static QTextCodeccodecForName (const QByteArray &name)
 Searches all installed QTextCodec objects and returns the one which best matches name; the match is case-insensitive. More...
 
static QTextCodeccodecForName (const char *name)
 Searches all installed QTextCodec objects and returns the one which best matches name; the match is case-insensitive. More...
 
static QTextCodeccodecForTr ()
 Returns the codec used by QObject::tr() on its argument. More...
 
static QTextCodeccodecForUtfText (const QByteArray &ba)
 Tries to detect the encoding of the provided snippet ba by using the BOM (Byte Order Mark) and returns a QTextCodec instance that is capable of decoding the text to unicode. More...
 
static QTextCodeccodecForUtfText (const QByteArray &ba, QTextCodec *defaultCodec)
 Tries to detect the encoding of the provided snippet ba by using the BOM (Byte Order Mark) and returns a QTextCodec instance that is capable of decoding the text to unicode. More...
 
static void setCodecForCStrings (QTextCodec *c)
 
static void setCodecForLocale (QTextCodec *c)
 Set the codec to c; this will be returned by codecForLocale(). More...
 
static void setCodecForTr (QTextCodec *c)
 
- Protected Functions inherited from QTextCodec
 QTextCodec ()
 Constructs a QTextCodec, and gives it the highest precedence. More...
 
virtual ~QTextCodec ()
 Destroys the QTextCodec. More...
 

Detailed Description

Definition at line 64 of file qsimplecodec_p.h.

Enumerations

◆ anonymous enum

anonymous enum
Enumerator
numSimpleCodecs 

Definition at line 70 of file qsimplecodec_p.h.

Constructors and Destructors

◆ QSimpleTextCodec()

QSimpleTextCodec::QSimpleTextCodec ( int  i)
explicit

Definition at line 618 of file qsimplecodec.cpp.

618  : forwardIndex(i), reverseMap(0)
619 {
620 }
QAtomicPointer< QByteArray > reverseMap

◆ ~QSimpleTextCodec()

QSimpleTextCodec::~QSimpleTextCodec ( )

Definition at line 623 of file qsimplecodec.cpp.

624 {
625  delete reverseMap;
626 }
QAtomicPointer< QByteArray > reverseMap

Functions

◆ aliases()

QList< QByteArray > QSimpleTextCodec::aliases ( ) const
virtual

Subclasses can return a number of aliases for the codec in question.

Standard aliases for codecs can be found in the IANA character-sets encoding file.

Reimplemented from QTextCodec.

Definition at line 717 of file qsimplecodec.cpp.

718 {
719  QList<QByteArray> list;
720  const char * const*a = unicodevalues[forwardIndex].aliases;
721  while (*a) {
722  list << *a;
723  ++a;
724  }
725  return list;
726 }
static const struct @2 unicodevalues[QSimpleTextCodec::numSimpleCodecs]
long ASN1_INTEGER_get ASN1_INTEGER * a

◆ convertFromUnicode()

QByteArray QSimpleTextCodec::convertFromUnicode ( const QChar input,
int  number,
ConverterState state 
) const
virtual

QTextCodec subclasses must reimplement this function.

Converts the first number of characters from the input array from Unicode to the encoding of the subclass, and returns the result in a QByteArray.

state can be 0 in which case the conversion is stateless and default conversion rules should be used. If state is not 0, the codec should save the state after the conversion in state, and adjust the remainingChars and invalidChars members of the struct.

Implements QTextCodec.

Definition at line 672 of file qsimplecodec.cpp.

673 {
674  const char replacement = (state && state->flags & ConvertInvalidToNull) ? 0 : '?';
675  int invalid = 0;
676 
677  if (!reverseMap){
679  if (!reverseMap.testAndSetOrdered(0, tmp))
680  delete tmp;
681  }
682 
683  QByteArray r(length, Qt::Uninitialized);
684  int i = length;
685  int u;
686  const QChar* ucp = in;
687  unsigned char* rp = (unsigned char *)r.data();
688  const unsigned char* rmp = (const unsigned char *)reverseMap->constData();
689  int rmsize = (int) reverseMap->size();
690  while(i--)
691  {
692  u = ucp->unicode();
693  if (u < 128) {
694  *rp = (char)u;
695  } else {
696  *rp = ((u < rmsize) ? (*(rmp+u)) : 0);
697  if (*rp == 0) {
698  *rp = replacement;
699  ++invalid;
700  }
701  }
702  rp++;
703  ucp++;
704  }
705 
706  if (state) {
707  state->invalidChars += invalid;
708  }
709  return r;
710 }
QAtomicPointer< QByteArray > reverseMap
ushort unicode() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qchar.h:251
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
static QByteArray * buildReverseMap(int forwardIndex)
quint16 u
bool testAndSetOrdered(T *expectedValue, T *newValue)
Atomic test-and-set.
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
int size() const
Returns the number of bytes in this byte array.
Definition: qbytearray.h:402

◆ convertToUnicode()

QString QSimpleTextCodec::convertToUnicode ( const char *  chars,
int  len,
ConverterState state 
) const
virtual

QTextCodec subclasses must reimplement this function.

Converts the first len characters of chars from the encoding of the subclass to Unicode, and returns the result in a QString.

state can be 0, in which case the conversion is stateless and default conversion rules should be used. If state is not 0, the codec should save the state after the conversion in state, and adjust the remainingChars and invalidChars members of the struct.

Implements QTextCodec.

Definition at line 653 of file qsimplecodec.cpp.

654 {
655  if (len <= 0 || chars == 0)
656  return QString();
657 
658  const unsigned char * c = (const unsigned char *)chars;
659 
660  QString r(len, Qt::Uninitialized);
661  QChar* uc = r.data();
662 
663  for (int i = 0; i < len; i++) {
664  if (c[i] > 127)
665  uc[i] = unicodevalues[forwardIndex].values[c[i]-128];
666  else
667  uc[i] = QLatin1Char(c[i]);
668  }
669  return r;
670 }
unsigned char c[8]
Definition: qnumeric_p.h:62
static const struct @2 unicodevalues[QSimpleTextCodec::numSimpleCodecs]
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ mibEnum()

int QSimpleTextCodec::mibEnum ( ) const
virtual

Subclasses of QTextCodec must reimplement this function.

It returns the MIBenum (see IANA character-sets encoding file for more information). It is important that each QTextCodec subclass returns the correct unique value for this function.

Implements QTextCodec.

Definition at line 728 of file qsimplecodec.cpp.

729 {
730  return unicodevalues[forwardIndex].mib;
731 }
static const struct @2 unicodevalues[QSimpleTextCodec::numSimpleCodecs]

◆ name()

QByteArray QSimpleTextCodec::name ( ) const
virtual

QTextCodec subclasses must reimplement this function.

It returns the name of the encoding supported by the subclass.

If the codec is registered as a character set in the IANA character-sets encoding file this method should return the preferred mime name for the codec if defined, otherwise its name.

Implements QTextCodec.

Definition at line 712 of file qsimplecodec.cpp.

713 {
714  return unicodevalues[forwardIndex].mime;
715 }
static const struct @2 unicodevalues[QSimpleTextCodec::numSimpleCodecs]

Properties

◆ forwardIndex

int QSimpleTextCodec::forwardIndex
private

◆ reverseMap

QAtomicPointer<QByteArray> QSimpleTextCodec::reverseMap
mutableprivate

Definition at line 84 of file qsimplecodec_p.h.

Referenced by convertFromUnicode(), and ~QSimpleTextCodec().


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