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

#include <qbig5codec.h>

Inheritance diagram for QBig5hkscsCodec:
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 70 of file qbig5codec.h.

Functions

◆ _aliases()

static QList<QByteArray> QBig5hkscsCodec::_aliases ( )
inlinestatic

Definition at line 73 of file qbig5codec.h.

Referenced by TWTextCodecs::aliases(), and TWTextCodecs::createForName().

◆ _mibEnum()

int QBig5hkscsCodec::_mibEnum ( )
static

Definition at line 1821 of file qbig5codec.cpp.

Referenced by TWTextCodecs::createForMib(), and TWTextCodecs::mibEnums().

1822 {
1823  return 2101;
1824 }

◆ _name()

QByteArray QBig5hkscsCodec::_name ( )
static

Definition at line 1827 of file qbig5codec.cpp.

Referenced by TWTextCodecs::createForName(), and TWTextCodecs::names().

1828 {
1829  return "Big5-HKSCS";
1830 }

◆ aliases()

QList<QByteArray> QBig5hkscsCodec::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 77 of file qbig5codec.h.

77 { return _aliases(); }
static QList< QByteArray > _aliases()
Definition: qbig5codec.h:73

◆ convertFromUnicode()

QByteArray QBig5hkscsCodec::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 1897 of file qbig5codec.cpp.

1898 {
1899  char replacement = '?';
1900  if (state) {
1901  if (state->flags & ConvertInvalidToNull)
1902  replacement = 0;
1903  }
1904 
1905  int invalid = 0;
1906 
1907  int rlen = 2*len + 1;
1908  QByteArray rstr;
1909  rstr.resize(rlen);
1910  uchar* cursor = (uchar*)rstr.data();
1911  for (int i = 0; i < len; i++) {
1912  unsigned short ch = uc[i].unicode();
1913  uchar c[2];
1914  if (ch < 0x80) {
1915  // ASCII
1916  *cursor++ = ch;
1917  } else if (qt_UnicodeToBig5hkscs(ch, c) == 2) {
1918  // Big5-HKSCS
1919  *cursor++ = c[0];
1920  *cursor++ = c[1];
1921  } else {
1922  // Error
1923  *cursor++ = replacement;
1924  }
1925  }
1926  rstr.resize(cursor - (uchar*)rstr.constData());
1927 
1928  if (state) {
1929  state->invalidChars += invalid;
1930  }
1931  return rstr;
1932 }
unsigned char c[8]
Definition: qnumeric_p.h:62
static int qt_UnicodeToBig5hkscs(uint wc, uchar *r)
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
void resize(int size)
Sets the size of the byte array to size bytes.

◆ convertToUnicode()

QString QBig5hkscsCodec::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 1833 of file qbig5codec.cpp.

1834 {
1835  uchar buf[2] = {0};
1836  int nbuf = 0;
1837  QChar replacement = QChar::ReplacementCharacter;
1838  if (state) {
1839  if (state->flags & ConvertInvalidToNull)
1840  replacement = QChar::Null;
1841  nbuf = state->remainingChars;
1842  buf[0] = state->state_data[0];
1843  buf[1] = state->state_data[1];
1844  }
1845  int invalid = 0;
1846 
1847  //qDebug("QBig5hkscsCodec::toUnicode(const char* chars = \"%s\", int len = %d)", chars, len);
1848  QString result;
1849  for (int i=0; i<len; i++) {
1850  uchar ch = chars[i];
1851  switch (nbuf) {
1852  case 0:
1853  if (IsLatin(ch)) {
1854  // ASCII
1855  result += QLatin1Char(ch);
1856  } else if (IsFirstByte(ch)) {
1857  // Big5-HKSCS
1858  buf[0] = ch;
1859  nbuf = 1;
1860  } else {
1861  // Invalid
1862  result += replacement;
1863  ++invalid;
1864  }
1865  break;
1866  case 1:
1867  if (IsSecondByte(ch)) {
1868  // Big5-HKSCS
1869  uint u;
1870  buf[1] = ch;
1871  if (qt_Big5hkscsToUnicode(buf, &u) == 2)
1872  result += QValidChar(u);
1873  else {
1874  // Error
1875  result += replacement;
1876  ++invalid;
1877  }
1878  } else {
1879  // Error
1880  result += replacement;
1881  ++invalid;
1882  }
1883  nbuf = 0;
1884  break;
1885  }
1886  }
1887  if (state) {
1888  state->remainingChars = nbuf;
1889  state->state_data[0] = buf[0];
1890  state->state_data[1] = buf[1];
1891  state->invalidChars += invalid;
1892  }
1893  return result;
1894 }
#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
unsigned int uint
Definition: qglobal.h:996
#define QValidChar(u)
Definition: qbig5codec.cpp:57
static int qt_Big5hkscsToUnicode(const uchar *s, uint *pwc)
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ mibEnum()

int QBig5hkscsCodec::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 78 of file qbig5codec.h.

78 { return _mibEnum(); }
static int _mibEnum()

◆ name()

QByteArray QBig5hkscsCodec::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 76 of file qbig5codec.h.

76 { return _name(); }
static QByteArray _name()

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