Qt 4.8
Public Functions | Static Public Functions | List of all members
QBig5Codec Class Reference

#include <qbig5codec.h>

Inheritance diagram for QBig5Codec:
QTextCodec

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...
 
- 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...
 

Static Public Functions

static QList< QByteArray_aliases ()
 
static int _mibEnum ()
 
static QByteArray _name ()
 
- 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)
 

Additional Inherited Members

- Public Types inherited from QTextCodec
enum  ConversionFlag { DefaultConversion, ConvertInvalidToNull = 0x80000000, IgnoreHeader = 0x1, FreeFunction = 0x2 }
 
- 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 56 of file qbig5codec.h.

Functions

◆ _aliases()

QList< QByteArray > QBig5Codec::_aliases ( )
static

Definition at line 1813 of file qbig5codec.cpp.

Referenced by TWTextCodecs::aliases(), aliases(), QBig5hkscsCodec::aliases(), QFontBig5Codec::aliases(), QFontBig5hkscsCodec::aliases(), and TWTextCodecs::createForName().

1814 {
1816  aliases += "Big5-ETen";
1817  aliases += "CP950";
1818  return aliases;
1819 }
QList< QByteArray > aliases() const
Subclasses can return a number of aliases for the codec in question.
Definition: qbig5codec.h:63

◆ _mibEnum()

int QBig5Codec::_mibEnum ( )
static

◆ _name()

QByteArray QBig5Codec::_name ( )
static

◆ aliases()

QList<QByteArray> QBig5Codec::aliases ( ) const
inlinevirtual

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 63 of file qbig5codec.h.

Referenced by _aliases().

63 { return _aliases(); }
static QList< QByteArray > _aliases()

◆ convertFromUnicode()

QByteArray QBig5Codec::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 1776 of file qbig5codec.cpp.

Referenced by mibEnum(), QBig5hkscsCodec::mibEnum(), QFontBig5Codec::mibEnum(), and QFontBig5hkscsCodec::mibEnum().

1777 {
1778  char replacement = '?';
1779  if (state) {
1780  if (state->flags & ConvertInvalidToNull)
1781  replacement = 0;
1782  }
1783 
1784  int invalid = 0;
1785 
1786  int rlen = 2*len + 1;
1787  QByteArray rstr;
1788  rstr.resize(rlen);
1789 
1790  uchar* cursor = (uchar*)rstr.data();
1791  for (int i=0; i<len; i++) {
1792  ushort ch = uc[i].unicode();
1793  uchar c[2];
1794  if (ch < 0x80) {
1795  // ASCII
1796  *cursor++ = ch;
1797  } else if (qt_UnicodeToBig5(ch, c) == 2 && c[0] >= 0xa1 && c[0] <= 0xf9) {
1798  *cursor++ = c[0];
1799  *cursor++ = c[1];
1800  } else {
1801  *cursor++ = replacement;
1802  ++invalid;
1803  }
1804  }
1805  rstr.resize(cursor - (uchar*)rstr.constData());
1806 
1807  if (state) {
1808  state->invalidChars += invalid;
1809  }
1810  return rstr;
1811 }
unsigned char c[8]
Definition: qnumeric_p.h:62
char * data()
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:429
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
unsigned char uchar
Definition: qglobal.h:994
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
unsigned short ushort
Definition: qglobal.h:995
void resize(int size)
Sets the size of the byte array to size bytes.
static int qt_UnicodeToBig5(ushort ch, uchar *buf)

◆ convertToUnicode()

QString QBig5Codec::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 1713 of file qbig5codec.cpp.

Referenced by mibEnum(), QBig5hkscsCodec::mibEnum(), QFontBig5Codec::mibEnum(), and QFontBig5hkscsCodec::mibEnum().

1714 {
1715  QChar replacement = QChar::ReplacementCharacter;
1716  uchar buf[2] = {0};
1717  int nbuf = 0;
1718  if (state) {
1719  if (state->flags & ConvertInvalidToNull)
1720  replacement = QChar::Null;
1721  nbuf = state->remainingChars;
1722  buf[0] = state->state_data[0];
1723  buf[1] = state->state_data[1];
1724  }
1725  int invalid = 0;
1726 
1727  //qDebug("QBig5Codec::toUnicode(const char* chars = \"%s\", int len = %d)", chars, len);
1728  QString result;
1729  for (int i=0; i<len; i++) {
1730  uchar ch = chars[i];
1731  switch (nbuf) {
1732  case 0:
1733  if (IsLatin(ch)) {
1734  // ASCII
1735  result += QLatin1Char(ch);
1736  } else if (IsFirstByte(ch)) {
1737  // Big5-ETen
1738  buf[0] = ch;
1739  nbuf = 1;
1740  } else {
1741  // Invalid
1742  result += replacement;
1743  ++invalid;
1744  }
1745  break;
1746  case 1:
1747  if (IsSecondByte(ch)) {
1748  // Big5-ETen
1749  uint u;
1750  buf[1] = ch;
1751  if (qt_Big5ToUnicode(buf, &u) == 2)
1752  result += QValidChar(u);
1753  else {
1754  // Error
1755  result += replacement;
1756  ++invalid;
1757  }
1758  } else {
1759  // Error
1760  result += replacement;
1761  ++invalid;
1762  }
1763  nbuf = 0;
1764  break;
1765  }
1766  }
1767  if (state) {
1768  state->remainingChars = nbuf;
1769  state->state_data[0] = buf[0];
1770  state->state_data[1] = buf[1];
1771  state->invalidChars += invalid;
1772  }
1773  return result;
1774 }
#define IsLatin(c)
Definition: qbig5codec.cpp:51
#define IsSecondByte(c)
Definition: qbig5codec.cpp:55
quint16 u
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
unsigned char uchar
Definition: qglobal.h:994
#define IsFirstByte(c)
Definition: qbig5codec.cpp:52
static int qt_Big5ToUnicode(const uchar *buf, uint *u)
unsigned int uint
Definition: qglobal.h:996
#define QValidChar(u)
Definition: qbig5codec.cpp:57
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ mibEnum()

int QBig5Codec::mibEnum ( ) const
inlinevirtual

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 64 of file qbig5codec.h.

64 { return _mibEnum(); }
static int _mibEnum()
Definition: qbig5codec.cpp:60

◆ name()

QByteArray QBig5Codec::name ( ) const
inlinevirtual

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 62 of file qbig5codec.h.

62 { return _name(); }
static QByteArray _name()
Definition: qbig5codec.cpp:65

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