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

#include <qjiscodec.h>

Inheritance diagram for QJisCodec:
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...
 
 QJisCodec ()
 
 ~QJisCodec ()
 
- 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 ()
 Returns the codec's mime name. More...
 
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 qjiscodec.h.

Constructors and Destructors

◆ QJisCodec()

QJisCodec::QJisCodec ( )
Warning
This function is not part of the public interface.

Definition at line 95 of file qjiscodec.cpp.

Referenced by mibEnum().

96 {
97 }
static QJpUnicodeConv * newConverter(int rule)
Definition: qjpunicode.cpp:727
const QJpUnicodeConv * conv
Definition: qjiscodec.h:99

◆ ~QJisCodec()

QJisCodec::~QJisCodec ( )
Warning
This function is not part of the public interface.

Definition at line 101 of file qjiscodec.cpp.

Referenced by mibEnum().

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

Functions

◆ _aliases()

QList< QByteArray > QJisCodec::_aliases ( )
static

Returns the codec's mime name.

Definition at line 358 of file qjiscodec.cpp.

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

359 {
360  QList<QByteArray> list;
361  list << "JIS7"; // Qt 3 compat
362  return list;
363 }

◆ _mibEnum()

int QJisCodec::_mibEnum ( )
static
Warning
This function is not part of the public interface.

Definition at line 344 of file qjiscodec.cpp.

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

345 {
346  return 39;
347 }

◆ _name()

QByteArray QJisCodec::_name ( )
static
Warning
This function is not part of the public interface.

Definition at line 350 of file qjiscodec.cpp.

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

351 {
352  return "ISO-2022-JP";
353 }

◆ aliases()

QList<QByteArray> QJisCodec::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 qjiscodec.h.

89 { return _aliases(); }
static QList< QByteArray > _aliases()
Returns the codec&#39;s mime name.
Definition: qjiscodec.cpp:358

◆ convertFromUnicode()

QByteArray QJisCodec::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 107 of file qjiscodec.cpp.

Referenced by mibEnum().

108 {
109  char replacement = '?';
110  if (cs) {
111  if (cs->flags & ConvertInvalidToNull)
112  replacement = 0;
113  }
114  int invalid = 0;
115 
116  QByteArray result;
117  Iso2022State state = Ascii;
118  Iso2022State prev = Ascii;
119  for (int i = 0; i < len; i++) {
120  QChar ch = uc[i];
121  uint j;
122  if (ch.row() == 0x00 && ch.cell() < 0x80) {
123  // Ascii
124  if (state != JISX0201_Latin ||
125  ch.cell() == ReverseSolidus || ch.cell() == Tilde) {
126  state = Ascii;
127  }
128  j = ch.cell();
129  } else if ((j = conv->unicodeToJisx0201(ch.row(), ch.cell())) != 0) {
130  if (j < 0x80) {
131  // JIS X 0201 Latin
132  if (state != Ascii ||
133  ch.cell() == YenSign || ch.cell() == Overline) {
134  state = JISX0201_Latin;
135  }
136  } else {
137  // JIS X 0201 Kana
138  state = JISX0201_Kana;
139  j &= 0x7f;
140  }
141  } else if ((j = conv->unicodeToJisx0208(ch.row(), ch.cell())) != 0) {
142  // JIS X 0208
143  state = JISX0208_1983;
144  } else if ((j = conv->unicodeToJisx0212(ch.row(), ch.cell())) != 0) {
145  // JIS X 0212
146  state = JISX0212;
147  } else {
148  // Invalid
149  state = UnknownState;
150  j = replacement;
151  ++invalid;
152  }
153  if (state != prev) {
154  if (state == UnknownState) {
155  result += Esc_Ascii;
156  } else {
157  result += Esc_SEQ[state - MinState];
158  }
159  prev = state;
160  }
161  if (j < 0x0100) {
162  result += j & 0xff;
163  } else {
164  result += (j >> 8) & 0xff;
165  result += j & 0xff;
166  }
167  }
168  if (prev != Ascii) {
169  result += Esc_Ascii;
170  }
171 
172  if (cs) {
173  cs->invalidChars += invalid;
174  }
175  return result;
176 }
virtual uint unicodeToJisx0212(uint h, uint l) const
Definition: qjpunicode.cpp:242
uint unicodeToJisx0201(uint h, uint l) const
Definition: qjpunicode.cpp:189
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 int uint
Definition: qglobal.h:996
static const char *const Esc_SEQ[]
Definition: qjiscodec.cpp:87
virtual uint unicodeToJisx0208(uint h, uint l) const
Definition: qjpunicode.cpp:221
uchar cell() const
Returns the cell (least significant byte) of the Unicode character.
Definition: qchar.h:283
static const char Esc_Ascii[]
Definition: qjiscodec.cpp:81
uchar row() const
Returns the row (most significant byte) of the Unicode character.
Definition: qchar.h:284
Iso2022State
Definition: qjiscodec.cpp:73
const QJpUnicodeConv * conv
Definition: qjiscodec.h:99

◆ convertToUnicode()

QString QJisCodec::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 178 of file qjiscodec.cpp.

Referenced by mibEnum().

179 {
180  uchar buf[4] = {0, 0, 0, 0};
181  int nbuf = 0;
182  Iso2022State state = Ascii, prev = Ascii;
183  bool esc = false;
184  QChar replacement = QChar::ReplacementCharacter;
185  if (cs) {
186  if (cs->flags & ConvertInvalidToNull)
187  replacement = QChar::Null;
188  nbuf = cs->remainingChars;
189  buf[0] = (cs->state_data[0] >> 24) & 0xff;
190  buf[1] = (cs->state_data[0] >> 16) & 0xff;
191  buf[2] = (cs->state_data[0] >> 8) & 0xff;
192  buf[3] = (cs->state_data[0] >> 0) & 0xff;
193  state = (Iso2022State)((cs->state_data[1] >> 0) & 0xff);
194  prev = (Iso2022State)((cs->state_data[1] >> 8) & 0xff);
195  esc = cs->state_data[2];
196  }
197  int invalid = 0;
198 
199  QString result;
200  for (int i=0; i<len; i++) {
201  uchar ch = chars[i];
202  if (esc) {
203  // Escape sequence
204  state = UnknownState;
205  switch (nbuf) {
206  case 0:
207  if (ch == '$' || strchr(Esc_CHARS, ch)) {
208  buf[nbuf++] = ch;
209  } else {
210  nbuf = 0;
211  esc = false;
212  }
213  break;
214  case 1:
215  if (buf[0] == '$') {
216  if (strchr(Esc_CHARS, ch)) {
217  buf[nbuf++] = ch;
218  } else {
219  switch (ch) {
220  case '@':
221  state = JISX0208_1978; // Esc $ @
222  break;
223  case 'B':
224  state = JISX0208_1983; // Esc $ B
225  break;
226  }
227  nbuf = 0;
228  esc = false;
229  }
230  } else {
231  if (buf[0] == '(') {
232  switch (ch) {
233  case 'B':
234  state = Ascii; // Esc (B
235  break;
236  case 'I':
237  state = JISX0201_Kana; // Esc (I
238  break;
239  case 'J':
240  state = JISX0201_Latin; // Esc (J
241  break;
242  }
243  }
244  nbuf = 0;
245  esc = false;
246  }
247  break;
248  case 2:
249  if (buf[1] == '(') {
250  switch (ch) {
251  case 'D':
252  state = JISX0212; // Esc $ (D
253  break;
254  }
255  }
256  nbuf = 0;
257  esc = false;
258  break;
259  }
260  } else {
261  if (ch == Esc) {
262  // Escape sequence
263  nbuf = 0;
264  esc = true;
265  } else if (ch == So) {
266  // Shift out
267  prev = state;
268  state = JISX0201_Kana;
269  nbuf = 0;
270  } else if (ch == Si) {
271  // Shift in
272  if (prev == Ascii || prev == JISX0201_Latin) {
273  state = prev;
274  } else {
275  state = Ascii;
276  }
277  nbuf = 0;
278  } else {
279  uint u;
280  switch (nbuf) {
281  case 0:
282  switch (state) {
283  case Ascii:
284  if (ch < 0x80) {
285  result += QLatin1Char(ch);
286  break;
287  }
288  /* fall through */
289  case JISX0201_Latin:
290  u = conv->jisx0201ToUnicode(ch);
291  result += QValidChar(u);
292  break;
293  case JISX0201_Kana:
294  u = conv->jisx0201ToUnicode(ch | 0x80);
295  result += QValidChar(u);
296  break;
297  case JISX0208_1978:
298  case JISX0208_1983:
299  case JISX0212:
300  buf[nbuf++] = ch;
301  break;
302  default:
303  result += QChar::ReplacementCharacter;
304  break;
305  }
306  break;
307  case 1:
308  switch (state) {
309  case JISX0208_1978:
310  case JISX0208_1983:
311  u = conv->jisx0208ToUnicode(buf[0] & 0x7f, ch & 0x7f);
312  result += QValidChar(u);
313  break;
314  case JISX0212:
315  u = conv->jisx0212ToUnicode(buf[0] & 0x7f, ch & 0x7f);
316  result += QValidChar(u);
317  break;
318  default:
319  result += replacement;
320  ++invalid;
321  break;
322  }
323  nbuf = 0;
324  break;
325  }
326  }
327  }
328  }
329 
330  if (cs) {
331  cs->remainingChars = nbuf;
332  cs->invalidChars += invalid;
333  cs->state_data[0] = (buf[0] << 24) + (buf[1] << 16) + (buf[2] << 8) + buf[3];
334  cs->state_data[1] = (prev << 8) + state;
335  cs->state_data[2] = esc;
336  }
337 
338  return result;
339 }
virtual uint jisx0208ToUnicode(uint h, uint l) const
Definition: qjpunicode.cpp:143
Definition: qjiscodec.cpp:59
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
#define QValidChar(u)
Definition: qjiscodec.cpp:71
Definition: qjiscodec.cpp:60
unsigned char uchar
Definition: qglobal.h:994
unsigned int uint
Definition: qglobal.h:996
uint jisx0201ToUnicode(uint h, uint l) const
Definition: qjpunicode.cpp:112
static const char Esc_CHARS[]
Definition: qjiscodec.cpp:79
virtual uint jisx0212ToUnicode(uint h, uint l) const
Definition: qjpunicode.cpp:161
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
Iso2022State
Definition: qjiscodec.cpp:73
const QJpUnicodeConv * conv
Definition: qjiscodec.h:99

◆ mibEnum()

int QJisCodec::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 qjiscodec.h.

90 { return _mibEnum(); }
static int _mibEnum()
Definition: qjiscodec.cpp:344

◆ name()

QByteArray QJisCodec::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 qjiscodec.h.

88 { return _name(); }
static QByteArray _name()
Definition: qjiscodec.cpp:350

Properties

◆ conv

const QJpUnicodeConv* QJisCodec::conv
protected

Definition at line 99 of file qjiscodec.h.

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


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