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

#include <qeuckrcodec.h>

Inheritance diagram for QEucKrCodec:
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
 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

Note
This class or function is reentrant.
Warning
This function is not part of the public interface.

Definition at line 77 of file qeuckrcodec.h.

Functions

◆ _aliases()

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

◆ _mibEnum()

int QEucKrCodec::_mibEnum ( )
static

◆ _name()

QByteArray QEucKrCodec::_name ( )
static

Definition at line 189 of file qeuckrcodec.cpp.

Referenced by KRTextCodecs::createForName(), name(), QCP949Codec::name(), QFontKsc5601Codec::name(), and KRTextCodecs::names().

190 {
191  return "EUC-KR";
192 }

◆ aliases()

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

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

◆ convertFromUnicode()

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

Reimplemented Function

Implements QTextCodec.

Definition at line 89 of file qeuckrcodec.cpp.

Referenced by mibEnum(), QCP949Codec::mibEnum(), and QFontKsc5601Codec::mibEnum().

90 {
91  char replacement = '?';
92  if (state) {
93  if (state->flags & ConvertInvalidToNull)
94  replacement = 0;
95  }
96  int invalid = 0;
97 
98  int rlen = 2*len + 1;
99  QByteArray rstr;
100  rstr.resize(rlen);
101  uchar* cursor = (uchar*)rstr.data();
102  for (int i = 0; i < len; i++) {
103  unsigned short ch = uc[i].unicode();
104  uint j;
105  if (ch < 0x80) {
106  // ASCII
107  *cursor++ = ch;
108  } else if ((j = qt_UnicodeToKsc5601(ch))) {
109  // KSC 5601
110  *cursor++ = (j >> 8) | 0x80;
111  *cursor++ = (j & 0xff) | 0x80;
112  } else {
113  // Error
114  *cursor++ = replacement;
115  ++invalid;
116  }
117  }
118  rstr.resize(cursor - (uchar*)rstr.constData());
119 
120  if (state) {
121  state->invalidChars += invalid;
122  }
123  return rstr;
124 }
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
unsigned char uchar
Definition: qglobal.h:994
unsigned int uint
Definition: qglobal.h:996
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)

◆ convertToUnicode()

QString QEucKrCodec::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 126 of file qeuckrcodec.cpp.

Referenced by mibEnum(), QCP949Codec::mibEnum(), and QFontKsc5601Codec::mibEnum().

127 {
128  uchar buf[2] = {0, 0};
129  int nbuf = 0;
130  QChar replacement = QChar::ReplacementCharacter;
131  if (state) {
132  if (state->flags & ConvertInvalidToNull)
133  replacement = QChar::Null;
134  nbuf = state->remainingChars;
135  buf[0] = state->state_data[0];
136  buf[1] = state->state_data[1];
137  }
138  int invalid = 0;
139 
140  QString result;
141  for (int i=0; i<len; i++) {
142  uchar ch = chars[i];
143  if (ch == 0)
144  break;
145  switch (nbuf) {
146  case 0:
147  if (ch < 0x80) {
148  // ASCII
149  result += QLatin1Char(ch);
150  } else if (IsEucChar(ch)) {
151  // KSC 5601
152  buf[0] = ch;
153  nbuf = 1;
154  } else {
155  // Invalid
156  result += replacement;
157  ++invalid;
158  }
159  break;
160  case 1:
161  // KSC 5601
162  if (IsEucChar(ch)) {
163  uint u = qt_Ksc5601ToUnicode((buf[0] << 8) | ch);
164  result += QValidChar(u);
165  } else {
166  // Error
167  result += replacement;
168  ++invalid;
169  }
170  nbuf = 0;
171  break;
172  }
173  }
174 
175  if (state) {
176  state->remainingChars = nbuf;
177  state->state_data[0] = buf[0];
178  state->state_data[1] = buf[1];
179  state->invalidChars += invalid;
180  }
181  return result;
182 }
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
unsigned int qt_Ksc5601ToUnicode(unsigned int code)
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ mibEnum()

int QEucKrCodec::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 85 of file qeuckrcodec.h.

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

◆ name()

QByteArray QEucKrCodec::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 83 of file qeuckrcodec.h.

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

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