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

The QCP949Codec class handles encoding and decoding of text in CP949 encoding. More...

#include <qeuckrcodec.h>

Inheritance diagram for QCP949Codec:
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
 Reimplemented Function More...
 
QString convertToUnicode (const char *, int, ConverterState *) const
 Reimplemented 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

The QCP949Codec class handles encoding and decoding of text in CP949 encoding.

Warning
This function is not part of the public interface.

CP949 stands for code page 949, default code page for Korean text on Windows.

Definition at line 91 of file qeuckrcodec.h.

Functions

◆ _aliases()

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

Definition at line 94 of file qeuckrcodec.h.

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

◆ _mibEnum()

int QCP949Codec::_mibEnum ( )
static

Definition at line 3393 of file qeuckrcodec.cpp.

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

3394 {
3395  return -949; // CP949 has no MIBenum. So we have to use fake value.
3396 }

◆ _name()

QByteArray QCP949Codec::_name ( )
static

Definition at line 3398 of file qeuckrcodec.cpp.

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

3399 {
3400  return "cp949";
3401 }

◆ aliases()

QList<QByteArray> QCP949Codec::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 98 of file qeuckrcodec.h.

98 { return _aliases(); }
static QList< QByteArray > _aliases()
Definition: qeuckrcodec.h:94

◆ convertFromUnicode()

QByteArray QCP949Codec::convertFromUnicode ( const QChar uc,
int  len,
ConverterState state 
) const
virtual

Reimplemented Function

Implements QTextCodec.

Definition at line 3406 of file qeuckrcodec.cpp.

3407 {
3408  char replacement = '?';
3409  if (state) {
3410  if (state->flags & ConvertInvalidToNull)
3411  replacement = 0;
3412  }
3413  int invalid = 0;
3414 
3415  int rlen = 2*len + 1;
3416  QByteArray rstr;
3417  rstr.resize(rlen);
3418  uchar* cursor = (uchar*)rstr.data();
3419  for (int i = 0; i < len; i++) {
3420  unsigned short ch = uc[i].unicode();
3421  uint j;
3422  if (ch < 0x80) {
3423  // ASCII
3424  *cursor++ = ch;
3425  } else if ((j = qt_UnicodeToKsc5601(ch))) {
3426  // KSC 5601
3427  *cursor++ = (j >> 8) | 0x80;
3428  *cursor++ = (j & 0xff) | 0x80;
3429  } else {
3430  const unsigned short *ptr = qBinaryFind(cp949_icode_to_unicode, cp949_icode_to_unicode + 8822, ch);
3431  if (ptr == cp949_icode_to_unicode + 8822) {
3432  // Error
3433  *cursor++ = replacement;
3434  ++invalid;
3435  }
3436  else {
3437  // The table 'cp949_icode_to_unicode' contains following
3438  // 1. Elements of row 81-a0 (32 rows) consisting of 178 elements each.
3439  // 2. Elements of row a1-fe not in EUC-KR consisting of 84 elements each.
3440  // On each row the elements are distributed (41-5A), (61-7A), (81-FE) in order.
3441  // http://www.microsoft.com/globaldev/reference/dbcs/949.mspx
3442 
3443  // find the position of the current unicode in the table.
3444  int internal_code = ptr - cp949_icode_to_unicode;
3445 
3446  int row, column;
3447  if(internal_code < 32 * 178) {
3448  // code between row 81-a0
3449  row = internal_code / 178;
3450  column = internal_code % 178;
3451  }
3452  else {
3453  // code between a1-fe
3454  internal_code -= 3008;
3455  row = internal_code / 84;
3456  column = internal_code % 84;
3457  }
3458 
3459  unsigned char first, second;
3460  first = row + 0x81;
3461 
3462  if(column < 26)
3463  second = column + 0x41; // between 41-5A
3464  else if(column < 52)
3465  second = column - 26 + 0x61; // between 61-7A
3466  else
3467  second = column - 52 + 0x81; // between 81-FE
3468 
3469  *cursor++ = first;
3470  *cursor++ = second;
3471  }
3472  }
3473  }
3474  rstr.resize(cursor - (uchar*)rstr.constData());
3475 
3476  if (state) {
3477  state->invalidChars += invalid;
3478  }
3479  return rstr;
3480 }
char * data()
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:429
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
Q_OUTOFLINE_TEMPLATE RandomAccessIterator qBinaryFind(RandomAccessIterator begin, RandomAccessIterator end, const T &value)
Definition: qalgorithms.h:295
unsigned char uchar
Definition: qglobal.h:994
unsigned int uint
Definition: qglobal.h:996
const T * ptr(const T &t)
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.
unsigned int qt_UnicodeToKsc5601(unsigned int unicode)
static const unsigned short cp949_icode_to_unicode[]
Definition: cp949codetbl.h:45

◆ convertToUnicode()

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

Reimplemented Function

Implements QTextCodec.

Definition at line 3485 of file qeuckrcodec.cpp.

3486 {
3487  uchar buf[2] = {0, 0};
3488  int nbuf = 0;
3489  QChar replacement = QChar::ReplacementCharacter;
3490  if (state) {
3491  if (state->flags & ConvertInvalidToNull)
3492  replacement = QChar::Null;
3493  nbuf = state->remainingChars;
3494  buf[0] = state->state_data[0];
3495  buf[1] = state->state_data[1];
3496  }
3497  int invalid = 0;
3498 
3499  QString result;
3500  for (int i=0; i<len; i++) {
3501  uchar ch = chars[i];
3502  if (ch == 0)
3503  break;
3504  switch (nbuf) {
3505  case 0:
3506  if (ch < 0x80) {
3507  // ASCII
3508  result += QLatin1Char(ch);
3509  } else if (IsEucChar(ch)) {
3510  // KSC 5601
3511  buf[0] = ch;
3512  nbuf = 1;
3513  } else if (IsCP949Char(ch)){
3514  buf[0] = ch;
3515  nbuf = 1;
3516  } else {
3517  // Invalid
3518  result += replacement;
3519  ++invalid;
3520  }
3521  break;
3522  case 1:
3523  // KSC 5601
3524  if (IsEucChar(ch) && !IsCP949Char(buf[0])) {
3525  uint u = qt_Ksc5601ToUnicode((buf[0] << 8) | ch);
3526  result += QValidChar(u);
3527  } else {
3528  // Rest of CP949
3529  int row, column;
3530  nbuf = 0;
3531  row = buf[0] - 0x81;
3532  if (0x41 <= ch && ch <= 0x5a)
3533  column = ch - 0x41;
3534  else if (0x61 <= ch && ch <= 0x7a)
3535  column = ch - 0x61 + 26;
3536  else if (0x81 <= ch && ch <= 0xfe)
3537  column = ch - 0x81 + 52;
3538  else {
3539  result += replacement;
3540  ++invalid;
3541  break;
3542  }
3543 
3544  int internal_code;
3545  if (row < 32)
3546  internal_code = row * 178 + column;
3547  else
3548  internal_code = 3008 + row * 84 + column;
3549  // check whether the conversion avialble in the table.
3550  if (internal_code < 0 || internal_code >= 8822) {
3551  result += replacement;
3552  ++invalid;
3553  break;
3554  }
3555  else
3556  result += QValidChar(cp949_icode_to_unicode[internal_code]);
3557  }
3558  nbuf = 0;
3559  break;
3560  }
3561  }
3562 
3563  if (state) {
3564  state->remainingChars = nbuf;
3565  state->state_data[0] = buf[0];
3566  state->state_data[1] = buf[1];
3567  state->invalidChars += invalid;
3568  }
3569  return result;
3570 }
quint16 u
#define IsEucChar(c)
Definition: qeuckrcodec.cpp:81
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 QValidChar(u)
Definition: qeuckrcodec.cpp:83
unsigned int uint
Definition: qglobal.h:996
#define IsCP949Char(c)
Definition: qeuckrcodec.cpp:82
unsigned int qt_Ksc5601ToUnicode(unsigned int code)
static const unsigned short cp949_icode_to_unicode[]
Definition: cp949codetbl.h:45
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ mibEnum()

int QCP949Codec::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 99 of file qeuckrcodec.h.

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

◆ name()

QByteArray QCP949Codec::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 97 of file qeuckrcodec.h.

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

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