Qt 4.8
Public Functions | Static Public Functions | Protected Variables | List of all members
QEucJpCodec Class Reference

#include <qeucjpcodec.h>

Inheritance diagram for QEucJpCodec:
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...
 
 QEucJpCodec ()
 Constructs a QEucJpCodec. More...
 
 ~QEucJpCodec ()
 Destroys the codec. 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)
 

Protected Variables

const QJpUnicodeConvconv
 

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 82 of file qeucjpcodec.h.

Constructors and Destructors

◆ QEucJpCodec()

QEucJpCodec::QEucJpCodec ( )

Constructs a QEucJpCodec.

Definition at line 93 of file qeucjpcodec.cpp.

Referenced by mibEnum().

94 {
95 }
const QJpUnicodeConv * conv
Definition: qeucjpcodec.h:99
static QJpUnicodeConv * newConverter(int rule)
Definition: qjpunicode.cpp:727

◆ ~QEucJpCodec()

QEucJpCodec::~QEucJpCodec ( )

Destroys the codec.

Definition at line 100 of file qeucjpcodec.cpp.

Referenced by mibEnum().

101 {
102  delete (QJpUnicodeConv*)conv;
103  conv = 0;
104 }
const QJpUnicodeConv * conv
Definition: qeucjpcodec.h:99

Functions

◆ _aliases()

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

◆ _mibEnum()

int QEucJpCodec::_mibEnum ( )
static

Definition at line 250 of file qeucjpcodec.cpp.

Referenced by _aliases(), JPTextCodecs::createForMib(), mibEnum(), and JPTextCodecs::mibEnums().

251 {
252  return 18;
253 }

◆ _name()

QByteArray QEucJpCodec::_name ( )
static

Definition at line 255 of file qeucjpcodec.cpp.

Referenced by JPTextCodecs::createForName(), name(), and JPTextCodecs::names().

256 {
257  return "EUC-JP";
258 }

◆ aliases()

QList<QByteArray> QEucJpCodec::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 89 of file qeucjpcodec.h.

89 { return _aliases(); }
static QList< QByteArray > _aliases()
Definition: qeucjpcodec.h:85

◆ convertFromUnicode()

QByteArray QEucJpCodec::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 106 of file qeucjpcodec.cpp.

Referenced by mibEnum().

107 {
108  char replacement = '?';
109  if (state) {
110  if (state->flags & ConvertInvalidToNull)
111  replacement = 0;
112  }
113  int invalid = 0;
114 
115  int rlen = 3*len + 1;
116  QByteArray rstr;
117  rstr.resize(rlen);
118  uchar* cursor = (uchar*)rstr.data();
119  for (int i = 0; i < len; i++) {
120  QChar ch = uc[i];
121  uint j;
122  if (ch.unicode() < 0x80) {
123  // ASCII
124  *cursor++ = ch.cell();
125  } else if ((j = conv->unicodeToJisx0201(ch.row(), ch.cell())) != 0) {
126  if (j < 0x80) {
127  // JIS X 0201 Latin ?
128  *cursor++ = j;
129  } else {
130  // JIS X 0201 Kana
131  *cursor++ = Ss2;
132  *cursor++ = j;
133  }
134  } else if ((j = conv->unicodeToJisx0208(ch.row(), ch.cell())) != 0) {
135  // JIS X 0208
136  *cursor++ = (j >> 8) | 0x80;
137  *cursor++ = (j & 0xff) | 0x80;
138  } else if ((j = conv->unicodeToJisx0212(ch.row(), ch.cell())) != 0) {
139  // JIS X 0212
140  *cursor++ = Ss3;
141  *cursor++ = (j >> 8) | 0x80;
142  *cursor++ = (j & 0xff) | 0x80;
143  } else {
144  // Error
145  *cursor++ = replacement;
146  ++invalid;
147  }
148  }
149  rstr.resize(cursor - (uchar*)rstr.constData());
150 
151  if (state) {
152  state->invalidChars += invalid;
153  }
154  return rstr;
155 }
virtual uint unicodeToJisx0212(uint h, uint l) const
Definition: qjpunicode.cpp:242
uint unicodeToJisx0201(uint h, uint l) const
Definition: qjpunicode.cpp:189
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
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
unsigned char uchar
Definition: qglobal.h:994
const QJpUnicodeConv * conv
Definition: qeucjpcodec.h:99
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.
virtual uint unicodeToJisx0208(uint h, uint l) const
Definition: qjpunicode.cpp:221
static const uchar Ss2
Definition: qeucjpcodec.cpp:82
uchar cell() const
Returns the cell (least significant byte) of the Unicode character.
Definition: qchar.h:283
static const uchar Ss3
Definition: qeucjpcodec.cpp:83
uchar row() const
Returns the row (most significant byte) of the Unicode character.
Definition: qchar.h:284

◆ convertToUnicode()

QString QEucJpCodec::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 158 of file qeucjpcodec.cpp.

Referenced by mibEnum().

159 {
160  uchar buf[2] = {0, 0};
161  int nbuf = 0;
162  QChar replacement = QChar::ReplacementCharacter;
163  if (state) {
164  if (state->flags & ConvertInvalidToNull)
165  replacement = QChar::Null;
166  nbuf = state->remainingChars;
167  buf[0] = state->state_data[0];
168  buf[1] = state->state_data[1];
169  }
170  int invalid = 0;
171 
172  QString result;
173  for (int i=0; i<len; i++) {
174  uchar ch = chars[i];
175  switch (nbuf) {
176  case 0:
177  if (ch < 0x80) {
178  // ASCII
179  result += QLatin1Char(ch);
180  } else if (ch == Ss2 || ch == Ss3) {
181  // JIS X 0201 Kana or JIS X 0212
182  buf[0] = ch;
183  nbuf = 1;
184  } else if (IsEucChar(ch)) {
185  // JIS X 0208
186  buf[0] = ch;
187  nbuf = 1;
188  } else {
189  // Invalid
190  result += replacement;
191  ++invalid;
192  }
193  break;
194  case 1:
195  if (buf[0] == Ss2) {
196  // JIS X 0201 Kana
197  if (IsKana(ch)) {
198  uint u = conv->jisx0201ToUnicode(ch);
199  result += QValidChar(u);
200  } else {
201  result += replacement;
202  ++invalid;
203  }
204  nbuf = 0;
205  } else if (buf[0] == Ss3) {
206  // JIS X 0212-1990
207  if (IsEucChar(ch)) {
208  buf[1] = ch;
209  nbuf = 2;
210  } else {
211  // Error
212  result += replacement;
213  ++invalid;
214  nbuf = 0;
215  }
216  } else {
217  // JIS X 0208-1990
218  if (IsEucChar(ch)) {
219  uint u = conv->jisx0208ToUnicode(buf[0] & 0x7f, ch & 0x7f);
220  result += QValidChar(u);
221  } else {
222  // Error
223  result += replacement;
224  ++invalid;
225  }
226  nbuf = 0;
227  }
228  break;
229  case 2:
230  // JIS X 0212
231  if (IsEucChar(ch)) {
232  uint u = conv->jisx0212ToUnicode(buf[1] & 0x7f, ch & 0x7f);
233  result += QValidChar(u);
234  } else {
235  result += replacement;
236  ++invalid;
237  }
238  nbuf = 0;
239  }
240  }
241  if (state) {
242  state->remainingChars = nbuf;
243  state->state_data[0] = buf[0];
244  state->state_data[1] = buf[1];
245  state->invalidChars += invalid;
246  }
247  return result;
248 }
virtual uint jisx0208ToUnicode(uint h, uint l) const
Definition: qjpunicode.cpp:143
quint16 u
#define IsEucChar(c)
Definition: qeucjpcodec.cpp:86
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
const QJpUnicodeConv * conv
Definition: qeucjpcodec.h:99
unsigned int uint
Definition: qglobal.h:996
#define QValidChar(u)
Definition: qeucjpcodec.cpp:88
uint jisx0201ToUnicode(uint h, uint l) const
Definition: qjpunicode.cpp:112
virtual uint jisx0212ToUnicode(uint h, uint l) const
Definition: qjpunicode.cpp:161
static const uchar Ss2
Definition: qeucjpcodec.cpp:82
static const uchar Ss3
Definition: qeucjpcodec.cpp:83
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
#define IsKana(c)
Definition: qeucjpcodec.cpp:85

◆ mibEnum()

int QEucJpCodec::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 90 of file qeucjpcodec.h.

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

◆ name()

QByteArray QEucJpCodec::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 88 of file qeucjpcodec.h.

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

Properties

◆ conv

const QJpUnicodeConv* QEucJpCodec::conv
protected

Definition at line 99 of file qeucjpcodec.h.

Referenced by convertFromUnicode(), convertToUnicode(), and ~QEucJpCodec().


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