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

#include <qsjiscodec.h>

Inheritance diagram for QSjisCodec:
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...
 
 QSjisCodec ()
 Creates a Shift-JIS codec. More...
 
 ~QSjisCodec ()
 Destroys the Shift-JIS 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 ()
 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 qsjiscodec.h.

Constructors and Destructors

◆ QSjisCodec()

QSjisCodec::QSjisCodec ( )

Creates a Shift-JIS codec.

Note that this is done automatically by the QApplication, you do not need construct your own.

Definition at line 73 of file qsjiscodec.cpp.

Referenced by mibEnum().

74 {
75 }
const QJpUnicodeConv * conv
Definition: qsjiscodec.h:99
static QJpUnicodeConv * newConverter(int rule)
Definition: qjpunicode.cpp:727

◆ ~QSjisCodec()

QSjisCodec::~QSjisCodec ( )

Destroys the Shift-JIS codec.

Definition at line 81 of file qsjiscodec.cpp.

Referenced by mibEnum().

82 {
83  delete (QJpUnicodeConv*)conv;
84  conv = 0;
85 }
const QJpUnicodeConv * conv
Definition: qsjiscodec.h:99

Functions

◆ _aliases()

QList< QByteArray > QSjisCodec::_aliases ( )
static

Returns the codec's mime name.

Definition at line 220 of file qsjiscodec.cpp.

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

221 {
222  QList<QByteArray> list;
223  list << "SJIS" // Qt 3 compat
224  << "MS_Kanji";
225  return list;
226 }

◆ _mibEnum()

int QSjisCodec::_mibEnum ( )
static

Definition at line 207 of file qsjiscodec.cpp.

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

208 {
209  return 17;
210 }

◆ _name()

QByteArray QSjisCodec::_name ( )
static

Definition at line 212 of file qsjiscodec.cpp.

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

213 {
214  return "Shift_JIS";
215 }

◆ aliases()

QList<QByteArray> QSjisCodec::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 qsjiscodec.h.

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

◆ convertFromUnicode()

QByteArray QSjisCodec::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 88 of file qsjiscodec.cpp.

Referenced by mibEnum().

89 {
90  char replacement = '?';
91  if (state) {
92  if (state->flags & ConvertInvalidToNull)
93  replacement = 0;
94  }
95  int invalid = 0;
96 
97  int rlen = 2*len + 1;
98  QByteArray rstr;
99  rstr.resize(rlen);
100  uchar* cursor = (uchar*)rstr.data();
101  for (int i = 0; i < len; i++) {
102  QChar ch = uc[i];
103  uint j;
104  if (ch.row() == 0x00 && ch.cell() < 0x80) {
105  // ASCII
106  *cursor++ = ch.cell();
107  } else if ((j = conv->unicodeToJisx0201(ch.row(), ch.cell())) != 0) {
108  // JIS X 0201 Latin or JIS X 0201 Kana
109  *cursor++ = j;
110  } else if ((j = conv->unicodeToSjis(ch.row(), ch.cell())) != 0) {
111  // JIS X 0208
112  *cursor++ = (j >> 8);
113  *cursor++ = (j & 0xff);
114  } else if ((j = conv->unicodeToSjisibmvdc(ch.row(), ch.cell())) != 0) {
115  // JIS X 0208 IBM VDC
116  *cursor++ = (j >> 8);
117  *cursor++ = (j & 0xff);
118  } else if ((j = conv->unicodeToCp932(ch.row(), ch.cell())) != 0) {
119  // CP932 (for lead bytes 87, ee & ed)
120  *cursor++ = (j >> 8);
121  *cursor++ = (j & 0xff);
122  } else if ((j = conv->unicodeToJisx0212(ch.row(), ch.cell())) != 0) {
123  // JIS X 0212 (can't be encoded in ShiftJIS !)
124  *cursor++ = 0x81; // white square
125  *cursor++ = 0xa0; // white square
126  } else {
127  // Error
128  *cursor++ = replacement;
129  ++invalid;
130  }
131  }
132  rstr.resize(cursor - (const uchar*)rstr.constData());
133 
134  if (state) {
135  state->invalidChars += invalid;
136  }
137  return rstr;
138 }
uint unicodeToSjis(uint h, uint l) const
Definition: qjpunicode.cpp:275
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
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
uint unicodeToSjisibmvdc(uint h, uint l) const
const QJpUnicodeConv * conv
Definition: qsjiscodec.h:99
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
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.
uchar cell() const
Returns the cell (least significant byte) of the Unicode character.
Definition: qchar.h:283
uint unicodeToCp932(uint h, uint l) const
uchar row() const
Returns the row (most significant byte) of the Unicode character.
Definition: qchar.h:284

◆ convertToUnicode()

QString QSjisCodec::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 140 of file qsjiscodec.cpp.

Referenced by mibEnum().

141 {
142  uchar buf[1] = {0};
143  int nbuf = 0;
144  QChar replacement = QChar::ReplacementCharacter;
145  if (state) {
146  if (state->flags & ConvertInvalidToNull)
147  replacement = QChar::Null;
148  nbuf = state->remainingChars;
149  buf[0] = state->state_data[0];
150  }
151  int invalid = 0;
152  uint u= 0;
153  QString result;
154  for (int i=0; i<len; i++) {
155  uchar ch = chars[i];
156  switch (nbuf) {
157  case 0:
158  if (ch < 0x80) {
159  result += QValidChar(ch);
160  } else if (IsKana(ch)) {
161  // JIS X 0201 Latin or JIS X 0201 Kana
162  u = conv->jisx0201ToUnicode(ch);
163  result += QValidChar(u);
164  } else if (IsSjisChar1(ch)) {
165  // JIS X 0208
166  buf[0] = ch;
167  nbuf = 1;
168  } else {
169  // Invalid
170  result += replacement;
171  ++invalid;
172  }
173  break;
174  case 1:
175  // JIS X 0208
176  if (IsSjisChar2(ch)) {
177  if ((u = conv->sjisibmvdcToUnicode(buf[0], ch))) {
178  result += QValidChar(u);
179  } else if ((u = conv->cp932ToUnicode(buf[0], ch))) {
180  result += QValidChar(u);
181  }
182  else if (IsUserDefinedChar1(buf[0])) {
183  result += QChar::ReplacementCharacter;
184  } else {
185  u = conv->sjisToUnicode(buf[0], ch);
186  result += QValidChar(u);
187  }
188  } else {
189  // Invalid
190  result += replacement;
191  ++invalid;
192  }
193  nbuf = 0;
194  break;
195  }
196  }
197 
198  if (state) {
199  state->remainingChars = nbuf;
200  state->state_data[0] = buf[0];
201  state->invalidChars += invalid;
202  }
203  return result;
204 }
#define IsUserDefinedChar1(c)
Definition: qsjiscodec.cpp:65
quint16 u
The QString class provides a Unicode character string.
Definition: qstring.h:83
const QJpUnicodeConv * conv
Definition: qsjiscodec.h:99
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
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
uint sjisibmvdcToUnicode(uint h, uint l) const
#define QValidChar(u)
Definition: qsjiscodec.cpp:67
uint cp932ToUnicode(uint h, uint l) const
#define IsKana(c)
Definition: qsjiscodec.cpp:61
uint sjisToUnicode(uint h, uint l) const
Definition: qjpunicode.cpp:264
#define IsSjisChar1(c)
Definition: qsjiscodec.cpp:62
#define IsSjisChar2(c)
Definition: qsjiscodec.cpp:64

◆ mibEnum()

int QSjisCodec::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 qsjiscodec.h.

90 { return _mibEnum(); }
static int _mibEnum()
Definition: qsjiscodec.cpp:207

◆ name()

QByteArray QSjisCodec::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 qsjiscodec.h.

88 { return _name(); }
static QByteArray _name()
Definition: qsjiscodec.cpp:212

Properties

◆ conv

const QJpUnicodeConv* QSjisCodec::conv
protected

Definition at line 99 of file qsjiscodec.h.

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


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